You can do it in 2 ways, they are:
1. Page.ClientScript.RegisterStartupScript() Method
2. Page.ClientScript.RegisterClientScriptBlock() Method
1. Page.ClientScript.RegisterStartupScript() Method
This class would be best used when you have a JavaScript function that you want to initiate when the page is loaded.
Ex:
Page.ClientScript.RegisterStartupScript(this.GetType(), "TestScript",
"function HelloWord() { alert('Hello World'); }", true);
btnTest.Attributes["onclick"] = "HelloWord()";
2. Page.ClientScript.RegisterClientScriptBlock() Method
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "MethodA",
"JSCollections.js");
www.codecollege.NET
Daily Tips- Tip #14 - How will associate a clientside script with Asp.net Button server control ?
0 comments
Post a Comment