Disabling the OkControlId On A ModalPopupExtender
I am using the ModalPopupExtender Ajax extender in .NET to display a modal dailog that takes in some data and saves it to the database. The issue is that the saving the data to the database is a little slow and there is an oppurtunity for the user to press the "Save" button a couple of times before the modal dialog closes. This is because I am handling the OnClick event of the save button, which writes the data and then calls the Hide method of the ModalPopupExtender. It looks a little like this:
<asp:Panel ID="panel" runat="server" Style="display: none;"> <asp:Button runat="server" Text="Save" Enabled="true" ID="saveButton" OnClick="saveButton_OnClick" /> <asp:Button runat="server" Text="Cancel" ID="cancelButton" OnClick="cancel_OnClick" /> </asp:Panel> <ajaxControlToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" PopupControlID="panel" TargetControlID="openButton" />Code Behind:
protected void saveButton_OnClick(object sender, EventArgs e) { ModalPopupExtender1.Hide(); // Do Some Work That Takes Time }No matter how fast I can write the data, a round trip needs to happen before the modal dialog is closed. To solve this problem I added a little client side code that gets injected OnPageLoad to disable the button right away.
saveButton.OnClientClick = String.Format("this.disabled=true; __doPostBack('{0}','');", saveButton.UniqueID);
{6230289B-5BEE-409e-932A-2F01FA407A92}
Why didn't you just inline that in the save button? Any specific reason for the codebehind vs. declarative?
ReplyDelete