【问题标题】:How to refresh currentpage with specific querystring value (c#)如何使用特定的查询字符串值刷新当前页面(c#)
【发布时间】:2011-02-20 19:36:33
【问题描述】:

我在删除特定产品时遇到了简单的错误通知问题。

我有一页 products.aspx 我有 2 个类别 - 手机(第 1 类) - 网(第 2 类)

当我从特定类别中删除特定产品时,我会收到一条通知“您的产品已被删除...”,然后 2 秒后,我希望刷新当前页面,因此新的和正确的数量产品展示。我的问题是,我在删除产品时请求查询字符串“deleteid”,然后我的带有“categoryid”的查询字符串当然是0。 总而言之,我需要“products.aspx?categoryid=2”来刷新,但在请求“deleteid”时,categoryid 是 ofc 0。

到目前为止,我已经知道了,希望您能理解并帮助我...谢谢!

... listing products by category (Request.QueryString["categoryid"])
... Then deleting by id, (Request.QueryString["deleteid"])    
... and now my problem and what I have so far:

var query = Request.QueryString["deleteid"];
    if (query.HasValue())
    {
        // deleting product
        DeleteSpecificProduct(query.Int16());

        errornotification.Text += @"Your product has been deleted";

        // refreshing current page
        var categoryid = Request.QueryString["categoryid"].Int16();
        var url = String.Format("products.aspx?categoryid={0}", categoryid);
        Response.AppendHeader("REFRESH", "2;URL=" + url);
     }

//谢谢

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    让删除链接包含categoryid。例如:

    <a href="products.aspx?deleteid=1&categoryid=1234">Delete Product 1</a>
    

    如果你不想这样做,你可以解析referrer url的查询字符串,假设删除链接是从分类页面点击的。

    附带说明,我认为您希望刷新元标记,而不是 http 标头。在页面的 &lt;head&gt; 部分中,添加

    <meta http-equiv="Refresh" content="2; URL=..." />
    

    【讨论】:

    【解决方案2】:

    你为什么不简单地Response.Redirect(String.Format("products.aspx?categoryid={0}", categoryid))你的页面通知错误?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-02
      • 2023-03-15
      • 2011-07-18
      • 2015-12-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-07
      • 1970-01-01
      相关资源
      最近更新 更多