Solved

What is Request("id")?

Posted on 2012-12-20
4
343 Views
Last Modified: 2012-12-26
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
Comment
Question by:AIBMass
4 Comments
 
LVL 3

Assisted Solution

by:Andy Green
Andy Green earned 100 total points
ID: 38710299
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 150 total points
ID: 38712841
Request("ID") can be from querystring, form, cookies or servervariables

http://msdn.microsoft.com/en-gb/library/system.web.httprequest.item.aspx
0
 
LVL 18

Assisted Solution

by:Gary Davis
Gary Davis earned 100 total points
ID: 38716256
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
 

Author Closing Comment

by:AIBMass
ID: 38721906
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now