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
3 Answers
Reset to default 2use 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
评论列表(0条)