Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

Posted Form Items not in Request

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Waldy - 08 Apr 2008 11:18 GMT
Hi there,
             I have a pure HTML form that is submitting data back to an
.ASPX form.  However, when I try to read the field values from the Request
object, the values are not there.

The Form has id, method and action set.  The fields have ids, but when I do
something like:

String avar = Request["FieldId"];

I only ever get null returned.  What am I missing?

Regards,

Steve W.
George Ter-Saakov - 08 Apr 2008 13:10 GMT
If you are not using .NET controls then you need to use name not id....

Like <input type="text" name="txtUser">
then Request["txtUser"] will work

Also they must be inside of <form> </form> tags.

PS: You can always check in debugger Request.Forms collection to see what is
being submitted.

George.

> Hi there,
>              I have a pure HTML form that is submitting data back to an
[quoted text clipped - 11 lines]
>
> Steve W.
Waldy - 08 Apr 2008 14:37 GMT
> If you are not using .NET controls then you need to use name not id....
>
> Like <input type="text" name="txtUser">
> then Request["txtUser"] will work
>
> Also they must be inside of <form> </form> tags.

Thanks George, that was it.
Mark Fitzpatrick - 08 Apr 2008 15:20 GMT
Don't ever, ever, ever use this method. You need to check the value by
Request.Form["FieldId"]. There are many reasons why. First, simply accessing
it by Request[] forces the system to scan all the possible locations,
including cookies, post method, get method, and server variables. This means
you never know where the value is coming from and could end up with garbage
or the wrong data, not to mention it leaves a form handler more open for
attack. Microsoft has issued warnings against using this method for almost a
decade. PHP had something similar with the register_globals option but they
disabled it by default years ago.

Second mistake, you always should test for nulls when accessing a form value
before assigning it or else you can throw errors. Best way to do this is:

string avar = string.Empty;

if(Request.["FieldId"] != null)
{
   avar = Request.["FieldId"].ToString();
}

That's the safest bet.

Also, which event are you checking for this in? It could be you are checking
too early and the request collection isn't populated fully (though doubtful
it's worth eliminating this possibility). If you're doing this in OnInit
maybe try it in OnLoad isntead.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression

> Hi there,
>              I have a pure HTML form that is submitting data back to an
[quoted text clipped - 11 lines]
>
> Steve W.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.