Thursday, January 17, 2008

ClientScript.RegisterStartupScript

We can run javascript on server side events by using ClientScript.RegisterStartupScript

The sample code shows sample use of the feature.

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Text;


 

public
partial
class
_Default : System.Web.UI.Page

{


protected
void Page_Load(object sender, EventArgs e)

{


StringBuilder sb = new
StringBuilder();


string myMessage = "Hello world!!";

sb.Append("<script language='javascript'>");

sb.Append("alert('" + myMessage + "');<");

sb.Append("/script>");

ClientScript.RegisterStartupScript(this.GetType(), "MsgSummary1", sb.ToString());


 

}

}

No comments: