【问题标题】:ModalPopupExtender calling .Show() does not workModalPopupExtender 调用 .Show() 不起作用
【发布时间】:2016-05-31 09:20:42
【问题描述】:

我使用的是 Visual Studio 2010,而对于数据库,我使用的是 Entity Framework 4。

在我的页面中,我有 3 个选项卡,在第二个选项卡中,我使用 Grid 视图来显示 Employee 的详细信息。在该网格视图中有 2 个图像按钮,一个用于删除另一个用于编辑。每当我单击编辑图像按钮时,我都想打开一个弹出框。

问题是 1.弹出框只出现一秒钟。 2.能够检索Grid视图的行索引。但是没有值传递到其他文本框中,它显示空值,即 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();

    }

代码运行没有错误,但模式弹出窗口不可见。请帮我找出我的错误。

【问题讨论】:

  • 尝试将您的标记代码,即您的面板放入 UpdatePanel。
  • @ManishGoswami 我也尝试过 UpdatePanel。

标签: c# asp.net modalpopupextender


【解决方案1】:

您可以通过更新面板使用 3 种方式来使用 Modal Popup。尝试其中任何一种。

  1. 在 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>

【讨论】:

  • @Kusum 检查我的更新答案,这肯定会对你有所帮助
  • 感谢在我的代码中使用了上述所有 3 个概念,但我的问题并未克服。所以请帮我找出错误。
  • 在更新面板中使用带有链接按钮的网格视图时,这是否同样有效?
【解决方案2】:

您使用的是最新版本的 AjaxControlToolkit 吗? 在 v16.1 中修复了以下错误:

【讨论】:

  • 是的,我正在使用最新版本的 AjaxControlToolkit(版本:16.1.0.0)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多