[英]ModalPopupExtender calling .Show() does not work
我使用的是 Visual Studio 2010,對於數據庫,我使用的是 Entity Framework 4。
在我的頁面中,我有 3 個選項卡,在第二個選項卡中,我使用網格視圖來顯示員工的詳細信息。 在該網格視圖中有 2 個圖像按鈕,一個用於刪除另一個用於編輯。 每當我單擊“編輯圖像按鈕”時,我都想打開一個彈出框。
問題是 1. 彈出框只出現一秒鍾。 2. 能夠檢索網格視圖的行索引。 但是沒有值傳遞到其他文本框,它顯示空值,即 name0.Text=""
在我的 .aspx 頁面中,我有以下內容
對於圖像按鈕
<asp:ImageButton ID="edit" runat="server" CommandArgument='<%# Bind("EmpID")%>' CommandName="edituser" ImageUrl="image/images.jpg" ToolTip="Edit User Details" OnClick="EditUser_Clicked"> </asp:ImageButton>
對於 ModalPopupExtender
<asp:ToolkitScriptManager ID="Toolkitmgr" runat="server"></asp:ToolkitScriptManager>
<asp:HiddenField ID="EmpID" runat="server"
onvaluechanged="EmpID_ValueChanged"/>
<asp:ModalPopupExtender ID="mpedit" DropShadow="true" BackgroundCssClass="modalBackground"
PopupControlID="pnedit" CancelControlID="btnCancel"
runat="server" TargetControlID="EmpID"></asp:ModalPopupExtender>
<asp:Panel runat="server" ID="pnedit" CssClass="modalPopup" Style="display: block;width:525px">
***Some Code***
</asp:Panel>
在 EditUser_Clicked 事件的服務器端代碼中,我有以下內容:
protected void EditUser_Clicked(object sender, EventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow row = (GridViewRow)btndetails.NamingContainer;
lblId.Text = GridView1.DataKeys[row.RowIndex].Value.ToString();
name0.Text = row.Cells[1].Text;
desig0.Text = row.Cells[2].Text;
dob0.Text = row.Cells[3].Text;
email0.Text = row.Cells[4].Text;
country0.Text = row.Cells[5].Text;
city0.Text = row.Cells[6].Text;
add0.Text = row.Cells[7].Text;
hq0.Text = row.Cells[8].Text;
rbtnListGender0.Text = row.Cells[9].Text;
mobno0.Text = row.Cells[10].Text;
this.mpedit.Show();
}
代碼運行沒有錯誤,但模式彈出窗口不可見。 請幫我找出我的錯誤。
有 3 種方法您可以使用更新面板使用模態彈出窗口。嘗試其中任何一種。
在 PopupPanel 中帶有 UpdatePanel 的模態彈出窗口
<div style="background-color: White"> <asp:Button runat="server" ID="button4" Text="Launch Modal Popup1" /> <asp:Panel runat="server" ID="modalPanel3" Style="display: none"> <asp:UpdatePanel runat="server" ID="updatePanel3"> <ContentTemplate> <asp:Label runat="server" ID="label4" Text="Label in UpdatePanel"></asp:Label> <asp:Button runat="server" ID="Button5" Text="Click to Cause postback" OnClick="Button5_Click" /> </ContentTemplate> </asp:UpdatePanel> <asp:Button runat="server" ID="Button6" Text="OK" /> <asp:LinkButton runat="server" ID="LinkButton1" Text="Cancel" /> </asp:Panel> <ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender3" TargetControlID="button4" PopupControlID="modalPanel3" OkControlID="Button6" CancelControlID="LinkButton1" BackgroundCssClass="modalBackground"> </ajaxToolkit:ModalPopupExtender> </div>
2.更新包含 ModalPopup 及其關聯的 PopupPanel 的面板
<asp:UpdatePanel runat="server" ID="updatePanel2" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button runat="server" ID="button2" Text="Launch Modal Popup2" />
<asp:Panel runat="server" ID="modalPanel2" BackColor="AliceBlue" Style="display: none">
<asp:Label runat="server" ID="label5" Text="Label in UpdatePanel"></asp:Label>
<asp:Button runat="server" ID="postbackBtn" Text="Click to Cause postback" OnClick="postbackBtn_Click" /><br />
<asp:Button runat="server" ID="cancelBtn2" Text="OK" />
<asp:LinkButton runat="server" ID="okBtn2" Text="Cancel" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender2" TargetControlID="button2"
PopupControlID="modalPanel2" OkControlID="okBtn2" CancelControlID="cancelBtn2"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
3.更新包含ModalPopup的面板; 它的 PopupPanel 里面有一個 UpdatePanel
<asp:UpdatePanel runat="server" ID="outerUpdatePanel" UpdateMode="Conditional" ChildrenAsTriggers="false">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="outerPanelTrigger" />
</Triggers>
<ContentTemplate>
<asp:Button runat="server" ID="outerPanelTrigger" Text="OuterPanelTrigger" /><br />
<br />
<asp:Button runat="server" ID="button1" Text="Launch Modal Popup3" />
<asp:Panel runat="server" ID="modalPanel1" BackColor="Pink" Style="display: none">
<asp:UpdatePanel runat="server" ID="updatePanel1" ChildrenAsTriggers="true" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label runat="server" ID="label1" Text="Label in UpdatePanel"></asp:Label>
<asp:Button runat="server" ID="updateLabel" OnClick="updateLabel_Click" Text="Click to Cause postback" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button runat="server" ID="okBtn" Text="OK" />
<asp:LinkButton runat="server" ID="cancelBtn" Text="Cancel" />
</asp:Panel>
<ajaxToolkit:ModalPopupExtender runat="server" ID="modalPopupExtender1" TargetControlID="button1"
PopupControlID="modalPanel1" OkControlID="okBtn" CancelControlID="cancelBtn"
BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
您使用的是最新版本的 AjaxControlToolkit 嗎? 在 v16.1 中修復了以下錯誤:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.