Click here to Skip to main content
15,896,912 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hi I want how to give alert message in asp.net (c#) code for the adding a records
it should ask whether it is add or not like that
Posted

if you are using update panel on the page use the below code.
C#
string script = " <script type=\"text/javascript\"> alert('" + message + "')   </script> ";
           
           ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", script, false);



if page doesn't contains ajax update panel, u can use this.
C#
this.Page.ClientScript.RegisterStartupScript(typeof(Page), "alert", script);
 
Share this answer
 
Just add the below after the record insertion code

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Message", "alert('Successfully Added')", true);


Considering the Comment from OP included code to show Confirmation Box
Add this to your pageload event
btnAdd.Attributes.Add("onclick",
       "return confirm('Do you want to Add?');");



Hope this helps you...
 
Share this answer
 
v2
Comments
PALLAVI D NAYAK 19-Dec-13 3:18am    
not like this i want to ask whether it is save or not
PALLAVI D NAYAK 19-Dec-13 3:33am    
alert message should ask before adding database if i click ok it should add database otherwise it should not add the database
JoCodes 19-Dec-13 4:16am    
Add this to your pageload event
btnAdd.Attributes.Add("onclick",
"return confirm('Do you want to Add?');");
JoCodes 19-Dec-13 6:01am    
Tried with the updated code for confirmation box?
You can use:-

string msg="This is my msg";
Response.Write("alert("+msg+")");

Hope, this will helps you....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900