ASP.NET: How to Display Yes No message box & handle response in C# ASP.NET

Please remember javascript is type sensitive & whenever you copy something from internet check the code again for example change the double quotation mark and inverted coma sign.

Code behind file, aspx.cs file:


Normal message box:
Response.Write(” alert(‘” + myStringVariable + “‘) “);

Yes no message box:
Response.Write(“confirm(‘Are you sure to continue?’);”);

Yes no response:

. I write the code for .aspx page.

=======================================================================    <asp:Button ID=”btnCommit” runat=”server” Text=”Commit”
OnClientClick=”if(!confirm(‘Are you quite sure?’)) return false;”
onclick=”btnCommit_Click” />=======================================================================

Copy and paste following code in your code behind(aspx.cs) page.
protected void Page_Load(object sender, EventArgs e)
protected void Button1_Click(object sender, EventArgs e)
Response.Write(“alert(‘Yes button clicked.’)”);

2nd method:

use javascript in .aspx

function confirm() 

if (confirm ==true) 
do something;
     return false;

then write in .aspx.cs
ButtonSave.Attributes.Add(“onclick”, “return confirm(‘Are you sure you proceed?’);”);



Leave a Reply

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

You are commenting using your 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