Request.Form Loop Question

  • Thread starter just.an.imbecile
  • Start date
J

just.an.imbecile

I have searched alot for this and cannot find an answer. I have a
simple form, and when it submits, I have it posting the data. I have a
simple function to loop through and print out all my form data:

<table class="data" width="90%">
<tr>
<th>Name</th>
<th>Value</th></tr>

<% string val;
foreach ( string name in Request.Form.AllKeys)
{
if (name != "" )
val = Request.Form[ name ] ;
else val = "&nbsp;"; %>
<tr>
<td><%= name %></td>
<td><%= val %></td></tr>
<% } %>
</table>

If that looks familiar, that is because I robbed it from a tutorial
site. :) Anyway, the problem is that I get garbage that looks like this
when I run it:

Name Value
__VIEWSTATE /wEPDwUJODI3NTcxMjc...
txtFName
txtLName
txtEmailBody
__EVENTVALIDATION wEWBALnqp3/DwK7zqYkArvO7sc...

I realize that I could just use if statements to ignore any names of
"__VIEWSTATE" or "__EVENTVALIDATION", but I was using some VB code
previously called gdform.asp, which did the same exact logic, but it
did not have to account for these two variables. What is going on, and
is there a cleaner way than using if statements to ignore these
variables?
Thanks in advance,
John
 
G

Guest

John,
In Asp.net there is feature what we call ViewState, This feature is used to
presist data between requests to the webserver for the particular page. Hence
you can notice that when you enter any value in server side control and when
the page is submitted to the server and comes again to the client, those
values are still in the control, this is all Handled by the ViewState. Now
coming to this Garbage looks, actually ViewState is Hashed Data, so if hacker
views the sourcecode he cant understand or temper it. You can Disable
ViewState by properties Window of Page
 
A

Andrew Robinson

asp.net as opposed to classic asp has a number of system generated hidden
fields such as view and the field used to validate the events. You are
retrieving these and these fields cannot be disabled. If you really want to
loop through all the fields on a page, I would suggest that you prefix your
fields with some unique name such as "MyField_" and then test for that when
you get a field.
 
H

Hans Kesting

asp.net as opposed to classic asp has a number of system generated hidden
fields such as view and the field used to validate the events. You are
retrieving these and these fields cannot be disabled. If you really want to
loop through all the fields on a page, I would suggest that you prefix your
fields with some unique name such as "MyField_" and then test for that when
you get a field.

Or the other way around: ignore if it starts with "__".

Hans Kesting
just.an.imbecile said:
I have searched alot for this and cannot find an answer. I have a
simple form, and when it submits, I have it posting the data. I have a
simple function to loop through and print out all my form data:

<table class="data" width="90%">
<tr>
<th>Name</th>
<th>Value</th></tr>

<% string val;
foreach ( string name in Request.Form.AllKeys)
{
if (name != "" )
val = Request.Form[ name ] ;
else val = "&nbsp;"; %>
<tr>
<td><%= name %></td>
<td><%= val %></td></tr>
<% } %>
</table>

If that looks familiar, that is because I robbed it from a tutorial
site. :) Anyway, the problem is that I get garbage that looks like this
when I run it:

Name Value
__VIEWSTATE /wEPDwUJODI3NTcxMjc...
txtFName
txtLName
txtEmailBody
__EVENTVALIDATION wEWBALnqp3/DwK7zqYkArvO7sc...

I realize that I could just use if statements to ignore any names of
"__VIEWSTATE" or "__EVENTVALIDATION", but I was using some VB code
previously called gdform.asp, which did the same exact logic, but it
did not have to account for these two variables. What is going on, and
is there a cleaner way than using if statements to ignore these
variables?
Thanks in advance,
John
 
J

just.an.imbecile

Thanks for all the advice. I will simply tell it not to get anything
that starts with __.

Andrew - Judging from the way you worded this "If you really want to
loop through all the fields on a page..." I'm assuming there is a
better way? I'm simply trying to gather the form info and then use it
to generate a simple email to myself.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top