Results 1 to 5 of 5

Thread: Is there a way to clear the QueryString before PostBack?

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276

    Resolved Is there a way to clear the QueryString before PostBack?

    I have a somewhat difficult problem...

    The project I have is complicated so I made a simpler example to explain.

    I have WebForm1.aspx with a Hyperlink control (Hyperlink1) and a Button control (Button1)

    The Hyperlink NavigateURL is WebForm1.aspx?id=0

    and the Page_Load and Button1_Click events are:
    Code:
    private void Page_Load(object sender, System.EventArgs e)
    {
    	if(Request.QueryString["id"] != null)
    	{
    		Response.Write(Request.QueryString["id"].ToString() + "<BR>");
    	}
    	else // do something else
    	{
    		Response.Write("id is null<BR>");
    	}
    }
    
    private void Button1_Click(object sender, System.EventArgs e)
    {
    	Page.RegisterClientScriptBlock("", "<script>alert('Button1 Click');</script>");
    	Response.Redirect("WebForm1.aspx");
    }
    Now, if I click the Hyperlink, I'm redirected back to the same page and the QueryString is shown in the Address Bar - http://localhost/QueryString/WebForm1.aspx?id=0

    and 0 is output at the top of the page.

    Next, I want to click Button1 but when the page reposts I want the QueryString variable "id" to be null or just be something different. The only way I could find to clear it is to just Redirect back to the page itself.

    The problem with that is, the code before the redirect won't show up on the page and any code after the redirect won't execute at all. If I comment out the Redirect line, the code executes, but the QueryString variable is still set.

    Last edited by wey97; Nov 10th, 2004 at 09:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width