Have you ever wanted to pop up an alert from server side code, or open a new window? This user control lets you execute any javascript command from Asp.Net
The benefits of using this control quickly become clear when you are able to programmatically open a new browser window, or use a javascript popup all based on server side processing. Its actually rather simple really, there are only 3 public properties that we deal with in the user control:
functionName (mandatory): this property will be the name of the function that is generated by the user control. You can then use this function name in the client side code. I usually use it in the body onload event so that the commands get fired when the page loads.
commands: this is an array list that you will populate with the javascript commands by using the Add() method of the arraylist.
refs: if you need any references to javascript source files (.js), you can use this property to Add() the any number of urls to source files
This control is meant to be placed in the head of the document because it will render javascript tags with a function bearing the name you supplied in the functionName property. By placing the name of the function in the onload event of the body tag, you are making sure that any javascript commands you add will be executed when the page loads, and if you haven't added any? then it simply does nothing.
"What if I have javascript functions in a javascript source file?"
Good question, that is what the refs property is for... you can add the url to your sourcefile by using the Add() method. Now that javascript is available to your script.
Here is a live demo of this user control in action.
Here is the source for that demo.
Here is the source for the user control.