Bonjour
J'ai le code suivant
Ceci me donne le résultat suivant dans mon code HTML rendu
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 StringBuilder cstext2 = new StringBuilder(); cstext2.Append("<script type=\"text/javascript\"> function DoClick() {"); cstext2.Append("alert('Hello World');} </"); cstext2.Append("script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "monscript", cstext2.ToString());
Je voudrais que le code javascript soit séparé du code HTML (donc mis dans un fichier à part, créer à la volé (comme le fait si bien la méthode ajax RegisterTypeForAjax)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>ClientScriptManager Example</title> </head> <body> <form name="Form2" method="post" action="JsClientScript.aspx" id="Form2"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTUxMTcwNzgxMGRk02elzZ6SCPnWb8OchB981uuRy/w=" /> </div> <input type="text" id="Message" /> <input type="button" value="ClickMe" onclick="DoClick()" /> <script type="text/javascript"> function DoClick() {alert('Hello World');} </script></form> </body> </html>
C'est posible ?
Merci d'avance
Partager