在ModalPopupExtender上执行服务器端代码
本文关键字:服务器端 代码 执行 ModalPopupExtender | 更新日期: 2023-09-27 18:07:50
我使用的是ASP。。NET和c#。我想弹出这个小屏幕,然后当OK按钮被点击,我想根据输入到弹出更新主屏幕。听起来应该是常态。这可能吗?如果可能,又是如何做到的?
<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>
服务器端不设置OkControlID
,使用ModalPopupExtender1.Hide()
。然后你可以先调用你的update-code。
你也应该使用服务器按钮,而不是<input id="btnOkay" type="button" value="Done" />
和处理他们的点击事件。
首先将asp:Button
添加为Ok按钮,并在您的aspx.cs页面中添加点击事件,如下所述:
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
}
然后从你的模态弹出扩展器中删除okcontrolid="btnOkay"
。