• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

What is Request("id")?

I am fairly new to ASP.NET and am trying to understand some code I am responsible for.

There are many references to Request("id") and also Request("ID") in this project. I understand that Request is the current System.Web.HttpRequest, but I don't understand what Request("id") is although I can see that refers it holds the id of different controls on the corresponding html.

1. Are Request("id") and Request("ID") the same thing? What do the values mean?
2. Are they a piece of ASP.NET or are they something in my project somewhere?
3. What would it mean for Request("id") to be nothing?

Thanks!
0
AIBMass
Asked:
AIBMass
3 Solutions
 
Andy GreenCommented:
Hi

I'm not familiar with just Request but it could be shorthand for either of the request objects.

Request.form - which while is still valid is 'Old School' way of getting values from the page to ther server. I say old school because in the ASP days this was how it was done.

The syntax is Request.Form(id") - the value will be that in a page control with the name of ID. If its not a text box or other it could be a hidden field. In .net youwould reference the value by referencing the control directly.

Request.Querystring("id") - This gets the valus from parameter call id in this instance from the URL. you might see www.google.com?id=1234. this would get the value 1234.

It is not case sensitive so ID & id will return the same value
0
 
CodeCruiserCommented:
Request("ID") can be from querystring, form, cookies or servervariables

http://msdn.microsoft.com/en-gb/library/system.web.httprequest.item.aspx
0
 
Gary DavisDir Internet SvcsCommented:
Yes, "id" and "ID" will return the same result. Normally, it is the value from the QueryString or Form though as CodeCruiser noted, the value can also be from the cookies or server variables. If you know what you want is from the QueryString, you could use Request.QueryString("id") or for form, you would use Request.Form("id").

The Request object is from ASP.Net but other languages would have something equivalent. Some other useful objects from ASP.Net would be Response, Server, Session and Application.

If the value returned is null, it means the Form, QueryString, etc did not exist. If the QueryString had something like http://www.server.com?id=&q=x then the response for the "id" would be and empty string, not null. If you want to treat null and empty as the same, you could use something like this in C#:

   var id = Request("id") ?? "";
   if (id.Length == 0) ...

Open in new window


Gary Davis
0
 
AIBMassAuthor Commented:
The code I am looking at (repeatedly as it's in many pages) is typically in Sub BindData and looks like:

If IsNothing(Request("ID") ) = false

    If Request("ID") <> some value
       Exit Sub
    End If

    ..... some logic that never gets executed apparently.....

else

    ... the logic that always get executed



So my conclusions are that the original developer was contemplating a scheme where only some of the page would be rebound, in accordance with what was in Request.Form("ID").

However, neither the original developer or anyone else ever implemented the use of this scheme - thus Request("ID") is always nothing and I am left with a bunch of extra code.

Thank you for your insights.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now