i want show javascript when user submit page. calling javascript through code behind (i think easy). here code:
messagebox1("testing message"); //calling function! private void messagebox1(string msg) //this in code behind of page. { // cleans message allow single quotation marks string cleanmessage = msg.replace("'", "\\'"); string script = "<script type=\"text/javascript\">alert('" + cleanmessage + "');</script>"; // gets executing web page page page = httpcontext.current.currenthandler page; // checks if handler page , script isn't allready on page if (page != null && !page.clientscript.isclientscriptblockregistered("alert")) { page.clientscript.registerclientscriptblock(typeof(commsetup), "alert", script); } }
this not working...what doing wrong here? thank you!
use static method pop alert:
public static void js_alert(string message) { // cleans message allow single quotation marks string cleanmessage = message.replace("'", "\\'"); string script = "<script type=\"text/javascript\">alert('" + cleanmessage + "');</script>"; // gets executing web page page page = httpcontext.current.currenthandler page; // checks if handler page , script isn't allready on page if (page != null && !page.clientscript.isclientscriptblockregistered("alert")) { page.clientscript.registerclientscriptblock(typeof(utilities), "alert", script); } }
edit: "utilities" should name of class place method in. mine happens called utilities. if putting in code-behind partial class, called whatever web page called .cs on end.
Comments
Post a Comment