Modal Popup Extender Show()方法不起作用

时间:2012-08-14 11:59:40

标签: c# asp.net ajaxcontroltoolkit modalpopupextender linkbutton

我有一个ListView LinkButton秒。我正在使用OnItemCommand方法和CommanName来打开对话框。

如果用户点击LinkButton,我想要打开一个对话框(带控件等)。但我每次都得到同样的错误:

  

System.InvalidOperationException:ListView“myListView”有一个   SelectedIndexChanging - 事件执行,未处理。

我的代码:aspx

...

<asp:HiddenField ID="hidForModel" runat="server" />

    <asp:scriptmanager id="ScriptManager1" runat="server">
       </asp:scriptmanager> 

       <asp:modalpopupextender id="PopUpDialog" 
                runat="server" cancelcontrolid="btnCancel" 
                okcontrolid="btnOkay" targetcontrolid="hidForModel" 
                popupcontrolid="Panel1" popupdraghandlecontrolid="PopupHeader" 
                drag="true" backgroundcssclass="ModalPopupBG" >

</asp:modalpopupextender>

            <div class="popupConfirmation" id="Panel1" runat="server" >
              <asp:Panel runat="server" ID="PopupHeader" CssClass="modalPopup">Benutzerinformationen</asp:Panel>
                <div class="Body">
                    Hallo
                    <asp:TextBox ID="txtVorname" runat="server"></asp:TextBox>
                    <asp:Button id="btnOkay" runat="server" text="Speichern" />
                    <asp:Button id="btnCancel" runat="server" text="Abbrechen" />
                </div>

            </div>

...

 <asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand">

        <LayoutTemplate>
            <table id="UserTable" runat="server" border="0" width="800" cellpadding="0" cellspacing="0">
                <tr style="background-color:#E5E5FE" class="TableClass">
                    <th id="th1" runat="server"><asp:LinkButton ID="lnkBenutzer" runat="server" >id_Benutzer</asp:LinkButton></th>
                    <th id="th2" runat="server"><asp:LinkButton ID="lnkemail" runat="server" >id_Email</asp:LinkButton></th>
                    <th id="th3" runat="server"><asp:LinkButton ID="lnkVorname" runat="server" >id_Vorname</asp:LinkButton></th>
                    <th id="th4" runat="server"><asp:LinkButton ID="lnkNachname" runat="server" >id_Nachname</asp:LinkButton></th>
                    <th id="th5" runat="server"><asp:LinkButton ID="lnkTelefon" runat="server" >id_Telefon</asp:LinkButton></th>
                </tr>
                <tr runat="server" id="ItemPlaceholder">
                </tr>
            </table>
        </LayoutTemplate>

        <ItemTemplate>

            <tr class="TableClass">    
                <td align="left" ><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server"  /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server"  /></td>

              <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </ItemTemplate>

        <AlternatingItemTemplate>

            <tr class="TableClass"> 

                <td align="left" ><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label1" Text='<%# Eval("Benutzername") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label2" Text='<%# Eval("eMail") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label3" Text='<%# Eval("Vorname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink"  CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label4" Text='<%# Eval("Nachname") %>' runat="server" /></td>
                <td align="left"><asp:LinkButton CssClass="MyLink" CommandName="Select" CommandArgument='<%# Container.DataItemIndex %>' ID="Label5" Text='<%# Eval("Telefonnummer") %>' runat="server" /></td>

                <td align="left"><asp:Label ID="Label6" Text='<%# Eval("GUID") %>' runat="server" Visible="False" /></td>

            </tr>

        </AlternatingItemTemplate>

        </asp:ListView>

...

c#c​​ode:

protected void myListView_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                txtVorname.Text = "test";

                PopUpDialog.Show();  //<-- Here is the error 

            }
        }

我可以使用Button(用于测试)打开对话框,但不能使用LinkButton打开对话框。

3 个答案:

答案 0 :(得分:2)

protected void myListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
 if (e.CommandName == "Select")
  {
  ModalPopupExtender popUp = (ModalPopupExtender)lvAlbum.FindControl("PopUpDialog");
  popUp.Show();
  }
}

答案 1 :(得分:1)

您只需处理SelectedIndexChanging中的ListView事件。

标记

<asp:ListView runat="server" ID="myListView" OnItemCommand="myListView_ItemCommand"
    OnSelectedIndexChanging="myListView_SelectedIndexChanging" >

代码隐藏:

protected void myListView_SelectedIndexChanging(object sender, EventArgs e)
{

}

ListView中的某些事件如果发生则需要处理。如果这些事件尝试触发(例如单击具有“CommandName”“Select”触发SelectedIndexChanging事件的列表项)并且它们未被处理,则会出现类似于您提到的错误。

答案 2 :(得分:0)

请勿使用命令文本Select。由于某种原因,它使弹出窗口不显示。 例如,执行以下操作:

if(e.CommandName == "ShowPopup")

这解决了我的问题。