0

I must be loosing it, but i'm not sure what :-)

i have a standard asp:button control with a code behind click event.

then, to prevent double click i disable the button on client click:

$('#<%=BTN_GCR_CheckCardValue2.ClientID %>').bind('click', function () {
 $('#<%=BTN_GCR_CheckCardValue2.ClientID %>').attr('disabled', 'disabled');
});

the disabled works, and the page posts back (enters the load event of the page), but doesn't enter the code behind event.

this jquery code is with the bind method, also tried it with click, same result.

what am i overlooking?

EDIT the button

<asp:Button ID="BTN_GCR_CheckCardValue2" runat="server" CssClass="individual_small_inputs"
                        OnClick="BTN_GCR_CheckCardValue2_Click" Text="CHECK" />

which leads to

<input type="submit" name="ctl00$ctl00$CPHMainSection$CPH_LeftSection$BTN_GCR_CheckCardValue2" value="CHECK" id="ctl00_ctl00_CPHMainSection_CPH_LeftSection_BTN_GCR_CheckCardValue2" class="individual_small_inputs" />
3
  • Can you please post the markup for the button as well? Commented May 19, 2011 at 17:58
  • do you use update panel? Commented May 19, 2011 at 18:06
  • it's webforms 4.0 by the way (if that makes any difference) Commented May 19, 2011 at 18:38

4 Answers 4

3

Disabled controls won’t get any events on the backend. First, disabling occurs. Then click event bubbles to the default handler and postback occurs. This is the reason for what you are seeing. As for posible custom solution… Try to simply make this button invisible (css property “visibility” set to hidden) with jquery instead of disabling it. If that will work, you can proceed with experiments. For instance, you can have container for your button with some kind of a message (like “In progress…”). Then set css property “position” to “absolute” value for your button. With this, your button will overlay the message. When button becomes invisible, user will see the message. Similar approach is used, for instance, here: http://s-c.me/ (Big “Highlight IT!” button). P.s. Sorry, I cannot send screnshots yet.

Sign up to request clarification or add additional context in comments.

1 Comment

aha, that's the reason. I indeed found out that making it invislbe worked, but i didn't know why...
2

If your intention is to prevent double posting same content, I would daresay this is not a good approach.


Have you heard about someone called Dave Ward and something called PostBack Ritalin?
Please try that. Its a super clean solution.

Comments

1

Final solution :D

$('#<%= BTN_GCR_CheckCardValue2.ClientID %>').click(function () {
        $(this).attr('disabled', 'disabled');
        $(this).parent().append($('<input />', {type: "hidden", name: $(this).attr('name') }));
});

12 Comments

now you mention, shouldn't there be something like that on the click event of the button (generated by asp.net?)
Yup, looks like jQuery is overriding it. View source and copy the __doPostBack code that ASP.NET puts in the inline onclick into your click handler.
@James: +0 for reusability :)
hmm, i think i don't get it: i removed the jqeury and there still is no postback click event on the button (which does work)...
there is a scriptmanager on the page ( <asp:ScriptManager ID="TTP_ScriptManager" runat="server" EnableScriptGlobalization="True" EnableScriptLocalization="True"> </asp:ScriptManager>), does that matter?
|
0

Not really the correct solution, but maybe put it in an setTimeout(function(){ ...disable... }, 1);.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.