通过回发传递参数到页面

发布于 12-10 07:03 字数 1628 浏览 1 评论 0原文

我得到了一个带有一些用户控件的 aspx 页面,所有这些控件都包含一个复选框。

将用户控件添加到页面时会选中该复选框。 该复选框设置为自动回发

我需要的是当自动回发发生时用户控件将消失。

首先我加载用户控件的方式: 我将它们作为表中的行加载,并为它们的 ID 值赋予它们代表的实体的值

   private void Load_Products(List<AppProduct> user_products)
    {
        HtmlTableRow row = null;
        foreach(AppProduct p in user_products)
        {
            row = new HtmlTableRow();
            tbl_products.Rows.Add(row);

            CartProduct prd = (CartProduct)Page.LoadControl("~/UserControls/CartProduct.ascx");

            prd.Title = p.Title;
            prd.Price = p.Price.ToString();
            prd.Pid = p.Pid.ToString();
            prd.ID = p.Pid.ToString();
            prd.State = 2;

            prd.Product_Checked += new EventHandler(prd_Product_Checked);

            HtmlTableCell cell = new HtmlTableCell();
            cell.Controls.Add(prd);
            row.Cells.Add(cell);
        }
    }   

CartProduct UserControl 代表 AppProduct 实体

现在我删除产品(用户控件)的方式是将其从列表中删除,如下所示:

    void prd_Product_Checked(object sender, EventArgs e)
    {      // this removes the product from the same list that the load products function gets
           ProductChangedEventArgs args = (ProductChangedEventArgs)e;
           cart.RemoveProduct(uid, args.Pid);                        
           Response.Redirect("~/Pages/cart.aspx");  
    }

现在这个有效,但似乎必须回发然后再次重定向才能影响从列表中删除发生在回发时,但会影响 仅在重新加载列表时加载下一页。 如果我可以知道如何在回发的页面加载期间从列表中删除该项目 无需再次重定向。

我有什么想法可以跳过重定向吗? 我想过也许可以通过回发发送参数,但我不知道这是否可能,因为这样我就可以发送产品 ID 并在调用 Load_Products 之前将其从列表中删除。

提前致谢 埃兰。

iv'e got an aspx page with some user controls , all of which contain a checkbox .

the checkbox is checked when the user control is added to the page.
the checkbox is set to auto post back

what i need is for when the auto post back occurs the user control will be gone.

first of all the way i load my user controls :
i load them as rows in a table and give their ID values the value of an entity that they represent

   private void Load_Products(List<AppProduct> user_products)
    {
        HtmlTableRow row = null;
        foreach(AppProduct p in user_products)
        {
            row = new HtmlTableRow();
            tbl_products.Rows.Add(row);

            CartProduct prd = (CartProduct)Page.LoadControl("~/UserControls/CartProduct.ascx");

            prd.Title = p.Title;
            prd.Price = p.Price.ToString();
            prd.Pid = p.Pid.ToString();
            prd.ID = p.Pid.ToString();
            prd.State = 2;

            prd.Product_Checked += new EventHandler(prd_Product_Checked);

            HtmlTableCell cell = new HtmlTableCell();
            cell.Controls.Add(prd);
            row.Cells.Add(cell);
        }
    }   

the CartProduct UserControl represents the AppProduct Entity

now the way i removed the product (usercontrol) was by removing it from the list as follows :

    void prd_Product_Checked(object sender, EventArgs e)
    {      // this removes the product from the same list that the load products function gets
           ProductChangedEventArgs args = (ProductChangedEventArgs)e;
           cart.RemoveProduct(uid, args.Pid);                        
           Response.Redirect("~/Pages/cart.aspx");  
    }

now this works , but it seems wrong to have to postback and then redirect again in order to take affect the removal from the list occur's on the post back , but takes affect
only on the next page load, when the list is re-loaded .
if i could some how remove the item from the list during the page load of the post back
with out having to re-direct again.

any ideas how i could skip the redirect ?
i thought of maybe sending arguments with the postback but i don't know if that's even possible , cause then i could send the product id and remove it from the list before Load_Products is called .

thanks in advance
eran.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

_蜘蛛2024-12-17 07:03:27

为什么不使用重定向再次调用 Load_Products 并使用更新后的产品列表,而不是重定向?

Instead of the Redirect why don't you simply call Load_Products again with the updated list of products?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文