[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

What is Request("id")?

Posted on 2012-12-20
4
Medium Priority
?
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Assisted Solution

by:Andy Green
Andy Green earned 400 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 600 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 400 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

656 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