CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Confirmation Message before Postback in Submit Button in ASP.Net
Submitted By Satheesh Babu B
On 10/31/2008 9:06:04 AM
Tags: CodeDigest,JavaScript  

Confirmation Message before Postback with Submit Button

 

When we are working with input forms, we will alert the user with a confirmation message before storing the data to the server.

From ASP.Net 2.0, we have a new property called ClientClick in server button control which can be utilized for this requirement.

 

All we have to do is, we need call the javascript confirm() box method with return statement.

 

Refer the code below,

 

<asp:Button ID="Button1" OnClientClick="javascript: return confirm('Are you sure to Continue?')" runat="server" Text="Save" />

 

The same thing can be achieved from code behind using ClientScriptManager class in ASP.Net 2.0.

 

if(!ClientScript.IsOnSubmitStatementRegistered("confirm"))

        ClientScript.RegisterOnSubmitStatement(this.GetType(),"confirm", "return confirm('Are you sure to proceed?')");

 

The above will code will give confirm box with OK and cancel button. Clicking OK will post the data to server while cancel will cancel the postback and will give the user to change the data in the input form.

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..