|
-
Jul 27th, 2004, 04:35 PM
#1
Thread Starter
Frenzied Member
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.
-
Jul 27th, 2004, 04:46 PM
#2
Frenzied Member
Try something like this
VB Code:
If Page.IsPostBack Then
Request.QueryString("id") = ""
End If
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 27th, 2004, 07:08 PM
#3
Thread Starter
Frenzied Member
Originally posted by Memnoch1207
Try something like this
VB Code:
If Page.IsPostBack Then
Request.QueryString("id") = ""
End If
I tried something similar but apparently the QueryString vars are Read-Only
-
Jul 28th, 2004, 02:13 AM
#4
VB Code:
If Page.IsPostBack Then
'Don't read the querystring!
Else
'whatever else...
End If
No?
-
Jul 28th, 2004, 07:45 AM
#5
Thread Starter
Frenzied Member
That works. I forgot IsPostBack would be reset on the link click even when the page is redirecting back to itself.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|