Solved

What is Request("id")?

Posted on 2012-12-20
4
342 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
varchar (max) 5 29
Server error in 'XXXXXXXX' application. 12 51
Re-position the objects 7 55
Entity Framework 3 16
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

12 Experts available now in Live!

Get 1:1 Help Now