调用.Show()的ModalPopupExtender不起作用

时间:2016-05-31 09:20:43

标签: c# asp.net modalpopupextender

我正在使用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();

    }

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

2 个答案:

答案 0 :(得分:1)

有三种方法可以使用Update Panel使用模态弹出窗口。请尝试以下任何一种方法。

  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. 2.Update Panel包含一个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.Update包含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>
    

答案 1 :(得分:0)

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