disabling asp button onclick prevents event from firing - asp.net

I'm trying to disable an asp button when it is clicked on the client side.
<asp:Button runat="server" ID="btnSubmit" Text="Save" class="Button" OnClick="btnSubmit_Click" CausesValidation="false"></asp:Button>
<script type="text/javascript">
$("input[type=submit],button").click(function (){$(this).attr("disabled", "disabled");});
</script>
when the button is clicked it does post back to the page_load , but it won't go to the btnSubmit_Click method. If I remove the jquery that disables the button it makes it from the page_load to the btnSubmit_Click method.
It seems when the button is disabled from the jquery it is no longer able to wire up to its event. Anyone have any ideas how I can disable the button client side, and still make it to the specific onclick event method?

This is resolved (Yuriy answered), the issue was that I needed to put the disabled code within the form.submit client side code. If not the disabled button was not firing its click event, yet it was still posting back, just not going to the onclick method.
solution:
$('#Form1').submit(function(){ $("input[type=submit],button").click(function (){$(this).attr("disabled", "disabled");});

Related

Submit button stops working after postback in IE11

Problem:
Sometimes submit button stops working after postback in IE11. It's
clickable, but it doesn't trigger any event. There is no script or
server side errors. Even the right click menu doesn't show on button.
If clicked somewhere on page it starts to work normally.
Button is general ASP.NET button
Server side:
<asp:Button ID="btnSave" runat="server" Text="Save" SkinID="Button82" OnClick="btnSave_Click" />
Client side:
<input name="ctl00$cphMain$Substitution$btnSave" class="button82" id="cphMain_Substitution_btnSave" type="submit" value="Save">
Any solutions?
For now I solved it using this in postback:
ScriptManager.RegisterStartupScript(Page, this.GetType(), "Refocus", "RefocusIE11()", true);
It calls function after postback, that refocuses on next element. This makes button to work again.

asp button and modal

So i have this button:
<asp:Button ID="Buttonid" runat="server" Text="View" BorderStyle="None" OnClick="Button_click_event" data-toggle="modal" data-target="#myModal"></asp:Button>
but then clicking the button will not toggle the OnClick Event, it will just show the modal.
But if i remove the data-toggle="modal" data-target="#myModal". The onclick event will work, but obviously the modal will not popup anymore.
Help please. Thanks
The script that is controlling your model more than likely stops the regular functions of the button so will stop it posting back which will stop the event handler from being fired.
To get both client side and server side to fire you'll have to post back and then display the model when the page reloads.

Onclick not added until after Postback

I have the following:
<asp:Button id="SubmitButton" Text="Submit" runat="server" OnClientClick="Do();"
OnClick="SubmitButton_Click"/>
When the page is first rendered, I go to the view source in my browser and see that the onclick="Do();" is not added to my submit button tag. But when I do a post back, and do the view source again, the onclick is added to the submit.
Why would the onclick not be there on the first request?
At least on my machine, I can see OnClick event on both request.

Reverse order of operations for OnClick and OnClientClick?

I have some simple javascript that I'd like to run when a button is clicked, but I also want some postback action to occur on the server. The logical code for this looks like this:
<asp:Button ID="btnOK" runat="server" Text="Save Changes" OnClientClick="UpdateParent();" OnClick="btnOK_Click" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClientClick="window.close();" />
<script language="javascript" type="text/javascript">
function UpdateParent()
{
window.opener.document.location.reload(true); // or should we postback instead?
window.close();
}
</script>
Basically, a popup window should refresh its parent and then close itself. However... if I call window.close(), the postback does not occur and the button handler is not called. But obviously OnClientClick is called before the postback happens. Am I going to have to emit this javascript in the button handler and run it when the page loads after postback? If so, what is the proper way to do this these days for ASP.NET 2.0?
It's a shame that the code above doesn't work as it's elegantly simple and straightforward.
You have to do the postback before closing the window. Also you want to do the postback before refreshing the parent window, as I guess that the reason to refresh the window is to display the information that you are about to save.
Use the RegisterStartupScript in the ClientScript object to run the code after postback:
Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "window.opener.location.reload(true);window.close();", true);
However, if the parent page is a result of a postback, this would cause a dialog window in the browser informing the user that a post request is needed to reload the page. To avoid this you would have to do something like calling a function in the parent page that could do a postback to update the page.

ASP.NET CheckBox disabling postback with javascript

I'm trying to wire up a CheckBox to handle an event when check/unchecked. If the user has JavaScript enabled, use that, otherwise use a postback.
Here is my code:
<asp:CheckBox ID="ApplicationInProcessCheckBox" runat="server"
Text="Application In Process" AutoPostBack="true"
oncheckedchanged="ApplicationInProcessCheckBox_CheckedChanged"
onclick="return false;" />
The return false in the javascript onclick event is disabling the postback. However, it also won't let the box check or uncheck. (I have more code to add to the javascript event... I just want to get the concept working first).
What am I doing wrong?
I think we can't post back on clicking checkbox without Javascript enabled.

Resources