Solved

What is Request("id")?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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