【问题标题】:Display modal popup from code behind error从错误后面的代码中显示模式弹出窗口
【发布时间】:2011-09-18 15:49:22
【问题描述】:

我有一个具有 ASP.NET 图像服务器控件 Id="imgCart" 的数据列表。现在我想在用户单击图像按钮时显示一个模式弹出窗口。由于每个产品必须有不同的描述,我需要从后面的代码中填充 gridview。下面是代码:

asp:DataList Id=:ImageList" OnItemCommand="Item_Command" > ItemTemplate > asp:ImageButton Id=: "imgcart"

代码背后:

protected void Item_Command(Object sender, DataListCommandEventArgs e)
    {

        ImageButton img = (ImageButton)e.Item.FindControl("imgcart");
        string idProduct = img.ToolTip.Trim();
        ModalPopupExtender1.Show();
    }

一切正常,预计不会显示模式弹出窗口。

模态弹出窗口的代码 [我已将其放在数据列表之外]

 <cc1:ModalPopupExtender ID="ModalPopupExtender1"
     PopupControlID="PopupPanel" TargetControlID="imgcart" 
    runat="server">
   </cc1:ModalPopupExtender>



  <asp:panel id="PopupPanel" runat="server" BorderStyle="Groove" 
   BorderColor="black" BorderWidth="3px" BackColor="AliceBlue" 
   Height="200px" Width="200px" style="display: none"> 
       <asp:Label ID="lblPopup" runat="server" Text="popup!"></asp:Label><br />
        <br />
      <asp:DropDownList ID="ddlData" runat="server">
       </asp:DropDownList><br />
                    <br />              
       <asp:Button ID="btnPopupOK" runat="server" Text="Ok" />             
       <asp:Button ID="btnPopupCancel" runat="server" Text="Cancel" />         
     </asp:panel> 

错误信息

System.InvalidOperationException: TargetControlID 的 “ModalPopupExtender1”无效。一种 无法使用 ID 为“imgcart”的控件 找到了。

请帮忙。我想从后面的代码中显示模态弹出窗口!!

编辑1

当我将 ajax modalpopup 放在数据列表中时,它会显示 modalpopup 但它不会转到后面的代码,我需要一个代码后面的事件来获取产品 ID。

【问题讨论】:

  • 我认为它无法将模式弹出窗口绑定到 imgcart 控件,因为运行时数据列表中没有此类控件,控件名称显示为某些 ctrl_contentplaceholder1 .....

标签: asp.net modalpopupextender


【解决方案1】:

添加一个带有Display:none 属性的按钮。

<asp:ImageButton ID="imgcart" runat="server" style="display:none;" />

希望对你有帮助。

【讨论】:

  • @Pankaj Agarwal 感谢您的回复,但对我没有帮助。我收到了同样的错误信息。
  • @Chris:请将 imgcart 按钮放在 DataList 之外。
  • @Pankaj Agarwal 恐怕我做不到,这是数据列表中每个产品的购物车图片,当用户点击此购物车图片时,我需要打开模式弹出窗口。
  • @Chris:我的意思是请创建一个像 id="btnDummy" 这样的虚拟按钮并设置 TargetControlID="btnDummy" 并设置 btnDummy 样式显示无。 btnDummy 应该在 DataList 之外。
  • @Pankaj Agarwal 在这种情况下它正在工作。现在我确定问题出在 Id [即imgcart] 因为在 rumtime 它期望它为 ctl00_ContentPlaceHolder1_ImageList_ctl01_imgcart
猜你喜欢
  • 2010-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多