javascript - Asp.Net button onclientclick problem - Stack Overflow

I have a strange problem, it seems, that I don't know how to solve.I have a button like this:<

I have a strange problem, it seems, that I don't know how to solve. I have a button like this:

<asp:Button ID="btnSave" runat="server" ClientIDMode="Static" Text="Save" OnClientClick="return ConfirmSave();" OnClick="btnSave_Click" />

If I write my client function like the following, it works as expected:

function ConfirmSave()
{
  return confirm('Confirm?');
}

But I should check, inside the function, for the confirm result, like this:

    function ConfirmSave() 
    {
      if (Page_ClientValidate('validationGroup'))
      {
        var conf = confirm("Confirm?");

        if (conf)
        {
             $('#btnSave').attr('disabled', 'disabled');
        }

        return conf;
      }
      else
        return false;
   }

Doing this, the page postback but the server click event doesn't fire.

Anyone could help? Thanks

I have a strange problem, it seems, that I don't know how to solve. I have a button like this:

<asp:Button ID="btnSave" runat="server" ClientIDMode="Static" Text="Save" OnClientClick="return ConfirmSave();" OnClick="btnSave_Click" />

If I write my client function like the following, it works as expected:

function ConfirmSave()
{
  return confirm('Confirm?');
}

But I should check, inside the function, for the confirm result, like this:

    function ConfirmSave() 
    {
      if (Page_ClientValidate('validationGroup'))
      {
        var conf = confirm("Confirm?");

        if (conf)
        {
             $('#btnSave').attr('disabled', 'disabled');
        }

        return conf;
      }
      else
        return false;
   }

Doing this, the page postback but the server click event doesn't fire.

Anyone could help? Thanks

Share Improve this question edited Aug 31, 2010 at 9:11 opaera asked Aug 31, 2010 at 7:35 opaeraopaera 211 silver badge3 bronze badges 2
  • ^^ In the if condition, kindly replace "-- do something" with what is being done actually. – Dienekes Commented Aug 31, 2010 at 8:30
  • Use this code onclientclick it may help: <asp:Button ID="btnSave" runat="server" ClientIDMode="Static" Text="Save" OnClientClick="if(!ConfirmSave() return false;" OnClick="btnSave_Click" /> – Saurabh Chauhan Commented Jul 22, 2015 at 7:49
Add a ment  | 

3 Answers 3

Reset to default 2

use a timeout to disable the button immediately after your code pletes and the submit happens.

if (conf) 
{ 
     setTimeout( function() { $('#btnSave').attr('disabled', 'disabled') }, 0 );
} 

Yes its fires because the Button is input with submit type.

You probably have some other error, maybe a duplicate of your button id, in the page (because you have set it on static mode).

Check if you have give the btnSave again somewhere else, or check also if you have any JavaScript error.

(After your page is render, on your browser see the source code of your page and search for the btnSave id if exist more than one time)

If you have a method called btnSave_Click() in your code behind then when you post back it will fall into your Page_load method first and then fall into that method. If you are using VB then you will need a method with Handles btnSave_Click() after it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745134062a4613114.html

相关推荐

  • javascript - Asp.Net button onclientclick problem - Stack Overflow

    I have a strange problem, it seems, that I don't know how to solve.I have a button like this:<

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信