Steve Staple
Steve Staple

Reputation: 3279

Execute server side code on ModalPopupExtender okcontrolid clicked

I am using ASP.NET and C#. I want to popup this little screen, then when the OK button is clicked, I want to update the main screen based on the input to the popup. Sounds like it should be a regular thing. Is it possible, and if so, how?

    <cc1:modalpopupextender id="ModalPopupExtender1" runat="server" 
cancelcontrolid="btnCancel" okcontrolid="btnOkay" 
targetcontrolid="txtCosCodeExpCode" popupcontrolid="Panel1" 
popupdraghandlecontrolid="PopupHeader" drag="true" 
backgroundcssclass="ModalPopupBG">
    </cc1:modalpopupextender>

    <asp:panel id="Panel1" style="display: none" runat="server">
<div class="CostCentreExpenseCodePopup" style="background-color:White ; border-style :solid;">
            <div class="PopupHeader" id="PopupHeader">Select Cost Centre / Expense Code</div>
            <div class="PopupBody">
                <p>Cost Centre<asp:DropDownList 
                                            ID="ddlCostCentres1" 
                                            runat="server" 
                                            CssClass="SVSComboBox1" 
                                            AppendDataBoundItems ="True"
                                            AutoPostBack="True" 
                                            style = "width :152px;"
                                            OnSelectedIndexChanged="ddlCostCentres1_SelectedIndexChanged">
                                            <asp:ListItem Text="Please select" Value="0"></asp:ListItem>
                                        </asp:DropDownList></p>

                <p>Expense Code <asp:DropDownList ID="ddlExpCode1" runat="server" CssClass="SVSComboBox1" style = "width :152px;"
                                            AppendDataBoundItems ="True" Enabled="False" Visible ="False">
                                            <asp:ListItem Text="Please select" Value="0"></asp:ListItem>
                                        </asp:DropDownList></p>
            </div>
            <div class="Controls">
                <input id="btnOkay" type="button" value="Done" />
                <input id="btnCancel" type="button" value="Cancel" />
    </div>
    </div>

Upvotes: 3

Views: 5509

Answers (2)

SpiderCode
SpiderCode

Reputation: 10122

First of all add the asp:Button as an Ok button and add click event in your aspx.cs page as mentioned below:

ASPX:

<asp:Button runat="server" ID="btnOkay" Text="OK" OnClick="btnOkay_Click"/>

ASPX.cs

protected void btnOkay_Click(object sender, EventArgs e)
{
    // Code to write on ok click event
}

And then remove okcontrolid="btnOkay" from your modal popup extender.

Upvotes: 0

Tim Schmelter
Tim Schmelter

Reputation: 460048

Don't set OkControlID but use ModalPopupExtender1.Hide() on server-side. Then you're able to call your update-code first.

You should also use server-buttons instead of <input id="btnOkay" type="button" value="Done" /> and handle their click-event.

Upvotes: 2

Related Questions