Xaisoft
Xaisoft

Reputation: 46651

What does the Request object do in the following scenario?

If I see something like:

if(Request["Email"])
{

}

What does this actually mean? Where is the Email collection member actually being set?

Upvotes: 0

Views: 201

Answers (4)

Juri
Juri

Reputation: 32930

Just some additions to the posts of the others.

To have things more explicitly you normally use Request.QueryString[...] for getting values from the QueryString, so when a GET request has been done and Request.Form[...] when a POST request is done. Although in the latter case you usually directly access the values of your server controls, since ASP.net uses the ViewState mechanism to load back on your controls when the request comes back from the client.

Upvotes: 0

Brian Duncan
Brian Duncan

Reputation: 500

It retrieves either the submited form values (POST) or the submitted querystring values (GET).

You would generally see it written as either Request.Form["Email"] or Request.Querystring[Email"] instead of just Request["Email"].

Example of Form (POST) method:

On the HTML or ASPX Page:

<form action="SomePage.aspx">
<input type="hidden" name="Email" value="[email protected]" />
<input type="Submit" value="Submit Form" />
</form>

Once the form has been submitted by clicking the Submit Form button you would retrieve the form values using Request.Form["Email"] (or just Request["Email"] for the lazy :))

Upvotes: 1

shahkalpesh
shahkalpesh

Reputation: 33484

See this for example.

Taken from the above link

All variables can be accessed directly by calling Request(variable) without the collection name. In this case, the Web server searches the collections in the following order:

  • QueryString
  • Form
  • Cookies
  • ClientCertificate
  • ServerVariables

Upvotes: 3

Darthg8r
Darthg8r

Reputation: 12685

It's retrieving the variable from get/post parameters.

somepage.aspx?blah=1

string blahValue = Request["blah"];

Console.WriteLine(blahValue);

> 1

Even more specificially:

Cookies, Form, QueryString or ServerVariables

http://msdn.microsoft.com/en-us/library/system.web.httprequest_members(VS.71).aspx

Upvotes: 4

Related Questions