Skip to content Skip to sidebar Skip to footer

JavaScript Function Definition In ASP User Control

Possible Duplicate: User control javascript I defined a JavaScript function inside a user control. If I have multiple instances of the user control on my .aspx page, how do I pr

Solution 1:

You'll want to use the Page.ClientScript manager.

The following code will only register your code once per a page.

if (!page.ClientScript.IsClientScriptBlockRegistered(tType, "MyScript"))
{
     page.ClientScript.RegisterClientScriptBlock(tType, "MyScript", sScript);
}

You can also make sure that *.js files get added only once

if (!page.ClientScript.IsClientScriptIncludeRegistered(tType, "MyScriptFile"))
{
     page.ClientScript.RegisterClientScriptInclude(tType,"MyScriptFile","MyJavaScript.js")
}

Solution 2:

Could you put the javascript code in a separate .js file and reference that common.js file from the web page or master page?


Post a Comment for "JavaScript Function Definition In ASP User Control"