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
protected void Page_Load(object sender, EventArgs e)
string someScript = "";
someScript = "";
Page.ClientScript.RegisterStartupScript(this.GetType(), "onload", someScript);
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

No comments: