Click here to Skip to main content
15,905,566 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to aspx and have such a scenario:

User will type in a textbox and when he clicks a button the page will be redirected to itself with the query string he typed into textbox.

Here is my code:
Response.Redirect("somepage.aspx?parameter=" + txtbox1.text,false);<br />


and during page load:
txtbox1.text = Request.QueryString["parameter"]<br />


It works succesful only for the first time. After user types something else into the textbox and clicks the button the querystring remains the same. What am I doing wrong?
Posted
Updated 26-Jul-10 2:43am
v2

I don't understand the purpose here. You don't need to use a query string to postback data to the same page. Look at ViewState or other forms of persistance.
 
Share this answer
 
As Mark, said, you don't need to use Query string while posting it back to itself. To add more, Query string is one of the way to maintain state and pass on information to another page.
In your case, if you postback to the same page, all the values are directly accessible to you in code behind. No need to use/give query string. Thats not the way/use of uery strings.
 
Share this answer
 
Try adding:

if (!Page.IsPostBack) txtbox1.text = Request.QueryString["parameter"]

Without it the text box will always have it's value set to the querystring value.

Guys, doing this isn't as daft as it may seem on first glance...for example Google will do this on their search results page to prepopulate the search text box with the current search terms.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900