Display a javascript alert (or run script) from code behind page.

Using Response.Write from an asp.Net web form might work but has some side effects so using the .Net ClientScriptBlock will allow you to insert your javascript cleanly. Here is a sample from some real code I wrote.


// Any any function that runs on PageLoad
string csName = “alert”;
string js = “alert(‘Customer has abuse tickets’);”;
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsStartupScriptRegistered(csName))
cs.RegisterStartupScript(this.GetType(),csName, js, true);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s