Execute server side code on ModalPopupExtender okcontrolid clicked

我只是一个虾纸丫 提交于 2019-12-11 01:37:57

问题


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>


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/24139053/execute-server-side-code-on-modalpopupextender-okcontrolid-clicked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!