The class presented in this article helps to write client side scripting inside .NET code.
string object to create a script which is as follows:
script+= "alert('Hello world');";
So, the class which I developed is very simple but helps the code to be a bit cleaner, and it's using
StringBuilder which is better when it comes to concatenating strings. Notice that we always have to begin script (
</script>), where we can make a mistake while typing our code. Using this class, you don't have to type the above mentioned tags in your scripts.
Using the code
Following is an example to use the class which I have developed.
ScriptHelper js = new ScriptHelper();
js.Add("alert('This is an example');");
Notice that you don't have to begin or end the
<script> tags. As mentioned earlier,
ScriptHelper is using
ScriptHelper object, by calling the constructor which takes one argument as
string which lets you specify the language of your script. A DLL for Visual Studio 2002 (1.0 framework) is included in the code. If anyone would like to use the code in 1.1, they can recompile the
ScriptHelper class in VS 2003. Sorry, I only have VS 2002 .
Points of Interest
Add method. That way, whenever you add a script using