Sat 19 Jul 2008
RegisterClientScriptBlock Example
Posted by admin under AJAX, CSharp Commands, javascript |
Whiel using the AJAXToolkit i came up with the situation where i needed to run some javascript after a server-side event was called. After poking around for a bit i found the command “ScriptManager.RegisterClientScriptBlock”. This command sends back asynchronously javascript that will be executed by the clients browser on update. Here is an example:-
string strscript = "var cbut=$get('programmaticPopup');alert(cbut.id+' '+cbut.style.position);"; ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "ToggleScript", strscript, true);
this.Page is your pages current Page object, “ToggleScript” is the name you are giving the script block, strscript is a string containg the javascript and following that is true which is there to tell the command to suround the inputed javascript with “”
p.s. you will notice the javascript command $get(elementname), this returns the object with the ID you gave it at design time just like document.getElementById();. If you look at the source of a running script all the ID tags have strange strings appended to the start of the ID name you gave it. $get finds the element without all the crap. Its part of the AJAX Toolkit.
No Responses to “ RegisterClientScriptBlock Example ”
Comments:
Leave a Reply
You must be logged in to post a comment.