0

I have a login page for a website where members insert their email in a textbox. My question is how to redirect to another page depending on the value of the textbox, for example

Response.Redirect("homepage.aspx?and here the value of the textbox");

2 Answers 2

5

keyboardP's answer is the correct one, but please keep in mind the security hole this opens in your site. You need to run that textbox value through all the validation you can to avoid XSS attacks, request hijacking, or any other malicious behavior that can done by simply using the value from a textbox without verifying it.

If this isn't an issue, you should mark keyboardP's answer as the right one.

Sign up to request clarification or add additional context in comments.

Comments

4
Response.Redirect(string.Format("homepage.aspx?{0}", myTextbox.Text));

All the code above does is replace {0} with the value of the textbox, which is retrieved using the Text property. The page is then redirected to the newly formed string which contains the textbox value.

As a side note, since I don't know what's in your textbox, you should add an ID for the querystring like this:

string.Format("homepage.aspx?mytextbox={0}", myTextbox.Text)

This makes it easier to retrieve the QueryString from the other side.

EDIT - To receive the QueryString, you handle it on the page that it's being redirected to. In that page, you could do something like this:

protected void Page_Load(object sender, EventArgs e)
{
    //notice that we're using the id `mytextbox`
    string qsvalue = Request.QueryString["mytextbox"];
    if (qsvalue != null)
    {
        ...
    }
}

I'm assuming it's a string, but you can also parse it to other types such as integers if that's what you're expecting.

2 Comments

that's great however i as doing this to be able to pass the value of the query string to some method, but i missing something, how to get the value of this querystring?
From your other page do Request.QueryString["mytextbox"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.