1

I want to add a confirmation message on button click , but btnUpdateEmail_Click not working now.

<asp:Button ID="btnSave" runat="server" UseSubmitBehavior="false" 
            Text="Update Import Email" ValidationGroup="groupValidation" 
            OnClientClick="return confirm('Are you sure you want to update 
            Import Email?');" OnClick="btnUpdateEmail_Click"   
            CssClass="btn-danger" Height="46px" Width="237px" 
            Font-Bold="true" />
Darren Reid
  • 2,322
  • 20
  • 25
  • 1
    Your provided code is working fine (I tested by adding a new aspx page in my web app and the confirmation is shown) – Usman Waheed Jun 23 '16 at 05:23
  • Possible duplicate of [OnclientClick and OnClick is not working at the same time?](http://stackoverflow.com/questions/2155048/onclientclick-and-onclick-is-not-working-at-the-same-time) – Smit Patel Jun 23 '16 at 05:55

2 Answers2

1

Using UseSubmitBehavior="true" nearly did the trick. Be sure to have your OnClientClick call set up correctly:

Code was using OnClientClick="return Validate();" which is incorrect. It should just be

<asp:Button ID="keyword" runat="server" Text="Search" TabIndex="1" 
OnClick="keywordSearch_Click" OnClientClick="if (!Validate()) { return false;};" />

If it is set up incorrectly, the OnClick function will not fire.

Also click here, for more.

Also you can find, onclientclick-and-onclick-is-not-working-at-the-same-time.

Community
  • 1
  • 1
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
1

You have to only change the value of UseSubmitBehavior from false to true.

I hope it will resolve your problem.

<asp:Button ID="btnSave" runat="server" UseSubmitBehavior="true" Text="Update Import Email" ValidationGroup="groupValidation" OnClientClick="return confirm('Are you sure you want to update Import Email?');" OnClick="btnUpdateEmail_Click"   CssClass="btn-danger" Height="46px" Width="237px" Font-Bold="true" />
  • UseSubmitBehavior="false" What exactly this will do – lipika chakraborty Jun 23 '16 at 05:51
  • By default asp button behavior is to post data on server (submit behavior) but if you want to disable this behavior and make it only perform client side work then you can use UseSubmitBehavior="false" You can achieve this thing from another way using jquery ajax method where your button call a client side java-script function and after that you use ajax call to invoke server side method. But that is too lengthy code. – Mohd Ismail Siddiqui Jun 23 '16 at 06:05
  • I just remove UseSubmitBehavior="true" and my code is working as by default its value is true – lipika chakraborty Jun 23 '16 at 11:55