<% @Page Language ="C#" Debug="true" %> <% @Import Namespace="System" %> <% @Import Namespace="System.Web" %> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1252" /> <title>OnClick on HtmlControl inline C#</title> <script runat="server"> protected void ahrefBG_Click(object sender, EventArgs e) { HtmlAnchor anchor = (HtmlAnchor)sender; h1Title.InnerText = "vous avez choisi l'image : " + anchor.Attributes["desc"]; } </script> </head> <form id="frmMain" runat="server"> Définir un nouveau fond d'écran , ---- , , , ---- , , </form> </html>
<% @Page Language="C#" Debug="true" %> <% @Import Namespace="System" %> <% @Import Namespace="System.Xml" %> <% @Import Namespace="System.IO" %> <% @Import Namespace="System.Xml.XPath" %> <script runat="server"> protected String chooseBG() { return "Hello"; } protected void chooseBackGround(string[] r) { try { //String[] r = { "agence3", "sheira", "fondK.jpg" }; String filename = "test.xml"; using (FileStream f = new FileStream(HttpContext.Current.Server.MapPath(filename), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (f.Length != 0) { XmlDocument doc = new XmlDocument(); doc.Load(f); XmlElement racine = doc.DocumentElement; // on vérifie d'abord que la balise groupe existe if (racine !null && racine.Name "groupe") { XmlNodeList noeudsAgence = racine.ChildNodes; if (noeudsAgence.Count > 0) { // on vérifie que le noeud n'existe pas avant de le créer bool agenceExist = false; bool utilisateurExist = false; foreach (XmlNode noeudAgence in noeudsAgence) { if (noeudAgence.Attributes["nom"].InnerText == r[0]) { agenceExist = true; foreach (XmlNode utilisateur in noeudAgence.ChildNodes) { Response.Write (utilisateur.InnerText); if (utilisateur.InnerText == r[1]) { utilisateurExist = true; utilisateur.Attributes["fond"].Value = r[2]; break; } } if (!utilisateurExist) { XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); noeudAgence.AppendChild(user); } } } if (!agenceExist) { XmlElement ag = doc.CreateElement("agence"); XmlAttribute attrNom = doc.CreateAttribute("nom"); attrNom.Value = r[0]; ag.SetAttributeNode(attrNom); XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); ag.AppendChild(user); racine.AppendChild(ag); } f.Close(); doc.Save(HttpContext.Current.Server.MapPath(filename)); } } } else { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "Utf-8", null); doc.AppendChild(declaration); XmlElement racine = doc.CreateElement("groupe"); XmlElement ag = doc.CreateElement("agence"); XmlAttribute attrNom = doc.CreateAttribute("nom"); attrNom.Value = r[0]; ag.SetAttributeNode(attrNom); XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); ag.AppendChild(user); racine.AppendChild(ag); doc.AppendChild(racine); doc.Save(f); } } } catch (Exception ex) { //Todo:gestion des exceptions } } </script> <HTML> <HEAD> <meta http-equiv="content-type" content="text/html; charset=windows-1252" /> <script language= "Javascript" type= "text/javascript" > function getVar (nomVariable) { var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&" if (infos.indexOf("#")!=-1) infos = infos.substring(0,infos.indexOf("#"))+"&" var variable=0 { nomVariable = nomVariable + "=" var taille = nomVariable.length if (infos.indexOf(nomVariable)!=-1) variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&")) } return variable } function setBackGround(strFond) { var groupe = getVar('groupe'); var nom = getVar('nom'); var data = []; data.push(groupe, nom); data.push(strFond); //alert (data.join(",")); alert("<%= chooseBG() %>; <% String[] r = { "agence4", "Olivier", "fondO.jpg" }; /*String agence = Request.Params["groupe"];*/ String prenom = Request.Params["nom"]; chooseBackGround(r); %> } </script> <script language= "C#" type= "text/C#" runat= "Server"> private void chooseBackgroud() { } </script> </HEAD> Définir un nouveau fond d'écran ---- , 1.1 , , , ---- ---- ---- , , , </HTML>
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question<form runat="server"> <!-- tes balises de saisie et de validation --> </form>
Click voir si tu oses
protected void ahrefChoose_Click(object sender, EventArgs e) { // ce que tu souhaites faire }
<% @Page Language="C#" Debug="true" %> <% @Import Namespace="System" %> <% @Import Namespace="System.Web" %> <% @Import Namespace="System.Xml" %> <% @Import Namespace="System.IO" %> <% @Import Namespace="System.Xml.XPath" %> <script runat="server"> public String chooseBG() { return "Hello"; } protected void ahrefChooseBackGround_Click(String fond) { try { //String[] r = { "agence3", "sheira", "fondK.jpg" }; String agence = HttpContext.Current.Request.Params["groupe"]; String prenom = HttpContext.Current.Request.Params["nom"]; String[] r = new String []{ agence, prenom, fond}; String filename = "test.xml"; using (FileStream f = new FileStream(HttpContext.Current.Server.MapPath(filename), FileMode.OpenOrCreate, FileAccess.ReadWrite)) { if (f.Length != 0) { XmlDocument doc = new XmlDocument(); doc.Load(f); XmlElement racine = doc.DocumentElement; // on vérifie d'abord que la balise groupe existe if (racine !null && racine.Name "groupe") { XmlNodeList noeudsAgence = racine.ChildNodes; if (noeudsAgence.Count > 0) { // on vérifie que le noeud n'existe pas avant de le créer bool agenceExist = false; bool utilisateurExist = false; foreach (XmlNode noeudAgence in noeudsAgence) { if (noeudAgence.Attributes["nom"].InnerText == r[0]) { agenceExist = true; foreach (XmlNode utilisateur in noeudAgence.ChildNodes) { Response.Write (utilisateur.InnerText); if (utilisateur.InnerText == r[1]) { utilisateurExist = true; utilisateur.Attributes["fond"].Value = r[2]; break; } } if (!utilisateurExist) { XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); noeudAgence.AppendChild(user); } } } if (!agenceExist) { XmlElement ag = doc.CreateElement("agence"); XmlAttribute attrNom = doc.CreateAttribute("nom"); attrNom.Value = r[0]; ag.SetAttributeNode(attrNom); XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); ag.AppendChild(user); racine.AppendChild(ag); } f.Close(); doc.Save(HttpContext.Current.Server.MapPath(filename)); } } } else { XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "Utf-8", null); doc.AppendChild(declaration); XmlElement racine = doc.CreateElement("groupe"); XmlElement ag = doc.CreateElement("agence"); XmlAttribute attrNom = doc.CreateAttribute("nom"); attrNom.Value = r[0]; ag.SetAttributeNode(attrNom); XmlElement user = doc.CreateElement("utilisateur"); user.InnerText = r[1]; XmlAttribute attrFond = doc.CreateAttribute("fond"); attrFond.Value = r[2]; user.SetAttributeNode(attrFond); ag.AppendChild(user); racine.AppendChild(ag); doc.AppendChild(racine); doc.Save(f); } } } catch (Exception ex) { //Todo:gestion des exceptions } } </script> <HTML> <HEAD> <meta http-equiv="content-type" content="text/html; charset=windows-1252" /> <script language= "Javascript" type= "text/javascript" > function getVar (nomVariable) { var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&" if (infos.indexOf("#")!=-1) infos = infos.substring(0,infos.indexOf("#"))+"&" var variable=0 { nomVariable = nomVariable + "=" var taille = nomVariable.length if (infos.indexOf(nomVariable)!=-1) variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&")) } return variable } function setBackGround(strFond) { var groupe = getVar('groupe'); var nom = getVar('nom'); var data = []; data.push(groupe, nom); data.push(strFond); //alert (data.join(",")); //alert("<%= chooseBG() %>; <% String[] r = { "agence4", "Olivier", "fondO.jpg" }; /*String agence = HttpContext.Current.Request.Params["groupe"];*/ String prenom = HttpContext.Current.Request.Params["nom"]; Response.Write(prenom); //chooseBackGround(r); %> } </script> </HEAD> <form runat="server"> Définir un nouveau fond d'écran ---- , , , , ---- ---- ---- , , , </form> </HTML>
<!-- il faut écrire comac --> Click voir si tu oses <!-- et pas comac --> Click voir si tu oses
<td width=5 height =5></td>
<tr width=25> <td width=5 height =5> </td> <td width=5 height =5> </td> <td width=5 height =5> </td> <td width=5 height =5> </td> </tr>
ImageUrl= "../images/fond1.jpg"dans ma fonction ahrefChooseBackGround_Click, j'en ai besoin pour connaître le nom de l'image ??