add

Saturday, February 21, 2009

Javascript call from Master page and content Page -Part I

Create a JavaScript function on the fly and call the JavaScript function in the MasterPage Page_Load() event
C#
protected void Page_Load(object sender, EventArgs e)
{
string someScript = "";
someScript = "";
Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript);
}
VB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim someScript As String = ""
someScript = ""
Page.ClientScript.RegisterStartupScript(Me.GetType(), "onload", someScript)
End Sub

The Page.ClientScript.RegisterStartupScript() allows you to emit client-side script blocks from code behind. More info can be found over here http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx

No comments: