开发者

How to refresh currentpage with specific querystring value (c#)

开发者 https://www.devze.com 2023-02-11 08:15 出处:网络
I have a problem with a simple error notification when I delete a specific product. I have one page products.aspx

I have a problem with a simple error notification when I delete a specific product.

I have one page products.aspx I have 2 categories - Mobile (cat 1) - Net (cat 2)

When i delete a specific product from a specific category I have a notification coming up "your product has been deleted..." and then after 2 sec, I want the current page to refresh, so the new and correct number of products is shown. My problem is, that I am requesting querystring "deleteid", while deleting the product, and then my querystring with "categoryid" is, of course, 0. All in all i need "products.aspx?categoryid=2" to refresh, but categoryid is ofc 0, when requesting "deleteid".

I got this so far, hope you understand and can help me... Thanks!

... 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);
     }

//Thanks


Have the delete links include the categoryid. For example:

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

If you do not want to do this, you may be able to parse the query string of the referrer url, assuming the delete link is clicked from the category page.

On a side note, i think you want the meta tag refresh, not a http header. Inside your <head> section of the page, add

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


Why don't you simply Response.Redirect(String.Format("products.aspx?categoryid={0}", categoryid)) your page notifying the error?

0

精彩评论

暂无评论...
验证码 换一张
取 消