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" />
<ajaxControlToolKit:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
    PopupControlID="panel" TargetControlID="openButton" />
Code Behind:
protected void saveButton_OnClick(object sender, EventArgs e)
    // 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);


  1. Why didn't you just inline that in the save button? Any specific reason for the codebehind vs. declarative?


Post a Comment

Popular posts from this blog

Yet once more into the breech (of altered programming logic)

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

How to convert SVG data to a Png Image file Using InkScape