4

I am working on a project for an IT class where I need to pass in a value on the query string in a php page and read it into a hidden field on an ASP page.

I currently am passing the parameter fine from the php page to ASP, but I am pretty new to .NET in general. How do I get the data out of the string and into a variable in C#? For example, if the url is blah.com/upload?username=washington, how would I get "washington" and save it into a hidden field? Thanks a ton.

Jergason

Edit

I knew it would be easy. Thanks a ton.

3
  • Do you really want to use a hidden field, or just store the result as a local (or perhaps class-level) variable? Commented Mar 14, 2009 at 17:55
  • Ok, seems that line was all you needed... Glad to help. Commented Mar 14, 2009 at 17:56
  • Yeah, it is a requirement for the class. Dunno why that would be better than storing it in a variable, but oh well. Commented Mar 14, 2009 at 19:06

4 Answers 4

13

It seems you just want:

string username = Request.QueryString["username"];
Sign up to request clarification or add additional context in comments.

Comments

4

You can add a hidden field in your aspx file:

<asp:HiddenField ID="username" runat="server" />

And in your code behind populate it from the request parameter:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        username.Value = Request["username"];
    }
}

2 Comments

Okay, now another question. What is the difference between <code>Request["username"]</code> and <code>Request.QueryString["username"]</code>?
Request["username"] looks in both QueryString and Form parameters (GET and POST).
4

This returns value from form elements :

string username = Request.Form["username"];

This returns value from querystring :

string username = Request.QueryString["username"];

This looks both form and querystring collections :

string username = Request["username"];

1 Comment

Good to know Request("username") searches both query string and form variables
-1
if session ("blnIsuSERGOOD") = False or  is null (session ("blnISuSERGoo")) = True then
Response.Redirect.Querystring("name")

1 Comment

Some explanation could be useful.

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.