Loading ...

Alert Box From ASPX Code-Behind Code | CodeAsp.Net

Alert Box From ASPX Code-Behind Code

 /5
0 (0votes)

In this blog I will explain how to open a JavaScript alert from Code-behind file.

I want to show ‘Welcome’ alert on page load. Below is my code:-

protected void Page_Load(object sender, EventArgs e)
{
     Response.Write("<script>alert('Welcome')</script>");
}

 

Happy Coding:)

Comments (5)

   
Vinz
Vinz
Using Response.Write is not recommended for writing javascripts specially if you are using AJAX. what I'm trying to point out is you shouldn't use response.write because it just inserts what you're doing on the page where you put it. this might break the the predefined ajax message that is returned from the server to the client. Instead I'll recommend you to use the ClientScript of the ScriptManager object to register scripts via code behind.
1/21/2010
 · 
by
   
mohit
Thanks.
ya i can use below code -
ClientScript.RegisterStartupScript(typeof(String), "test", " alert('Welcome'); ");
is it Fine
1/21/2010
 · 
by
   
Anonymous
Anonymous
Nice Artical!
1/21/2010
 · 
by
   
vivek_iit
good point raised by Vinz. Mohit, you should try to write longer and better quality articles.
7/25/2010
 · 
by
   
mohit
Thank you sir for your comment.Next time I will write articles and blogs with better quality.
7/26/2010
 · 
by

Top Posts