Posted Form Items not in Request

Posted Form Items not in Request

am 08.04.2008 12:18:50 von John Smith

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.

Re: Posted Form Items not in Request

am 08.04.2008 14:10:58 von George Ter-Saakov

If you are not using .NET controls then you need to use name not id....

Like
then Request["txtUser"] will work

Also they must be inside of

tags.

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

George.


"Waldy" wrote in message
news:%23$wRzHWmIHA.3780@TK2MSFTNGP06.phx.gbl...
> 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.
>

Re: Posted Form Items not in Request

am 08.04.2008 15:37:17 von John Smith

"George Ter-Saakov" wrote in message
news:OalrbGXmIHA.5280@TK2MSFTNGP02.phx.gbl...
> If you are not using .NET controls then you need to use name not id....
>
> Like
> then Request["txtUser"] will work
>
> Also they must be inside of

tags.

Thanks George, that was it.

Re: Posted Form Items not in Request

am 08.04.2008 16:20:48 von Mark Fitzpatrick

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

"Waldy" wrote in message
news:%23$wRzHWmIHA.3780@TK2MSFTNGP06.phx.gbl...
> 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.
>