1

对此问题的一些后续问题对我有很大帮助。 ListView 行为中的 ASP.NET AJAX 工具包 ModalPopupExtender

我的网站是一个商店,产品设置在一个类中,根据它们所在的类别进行调用。用户可以单击产品以获取有关它的信息,该信息将在新页面中打开。

我想使用模态弹出扩展器将此页面显示为弹出窗口,而不是导航到新页面。感谢上面的链接,我几乎可以实现这一点,我的问题是我无法在面板所在的列表视图之外调用方法“GetProducts”。

这是aspx页面

    <div id="Panel1" style="display: none;" class="popupConfirmation">
               <iframe id="frameeditexpanse" src="ProductDetails.aspx?productID=<%#:Item.ProductID%>" height="161" > // here is the error item does not exist in the context
               </iframe>
               <div class="popup_Buttons" style="display: none">
                  <input id="btnClose" value="Close" type="button" />
               </div>                                               
           </div>      

    <asp:ListView ID="productList" runat="server" DataKeyNames="ProductID"
    GroupItemCount="3" ItemType="Website.Models.Product" SelectMethod="GetProducts"> // method is called here

     <ajaxToolkit:ModalPopupExtender runat="server" ID="ModalPopupExtender1"
          CancelControlID="btnClose" TargetControlID="PopUpPage"
          PopupControlID="Panel1"  Drag="true" BackgroundCssClass="ModalPopupBG" 
          PopupDragHandleControlID="PopupHeader" >
     </ajaxToolkit:ModalPopupExtender>   

<asp:ImageButton ID="PopUpPage" runat="server" 
   src="<%#:Item.ImagePath%>" width="100" height="75" /> // button the user clicks to open the pop up of the product description page

以及页面背后的代码(如果有帮助)

  public partial class ProductList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        public IQueryable<Product> GetProducts([QueryString("id")] int? categoryId)
        {
            var _db = new Website.Models.ProductContext();
            IQueryable<Product> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {

                query = query.Where(p => p.CategoryID == categoryId);
            }
            return query;
        }

    }

我尝试将 iframe 包装在 formview 中,以便我可以再次调用该方法,但这告诉我我只能调用一次,我还尝试在页面加载部分调用该方法,但没有任何乐趣,还有很多其他导致更多的事情错误。

任何帮助将不胜感激。

4

0 回答 0