468,545 Members | 1,716 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,545 developers. It's quick & easy.

Request.Form Loop Question

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

May 10 '06 #1
4 13280
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

"just.an.imbecile" wrote:
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 = " "; %>
<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

May 10 '06 #2
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.

--

Andrew Robinson
www.binaryocean.com
"just.an.imbecile" <jo******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

May 10 '06 #3
> 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.

--

Andrew Robinson
www.binaryocean.com

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

Hans Kesting
"just.an.imbecile" <jo******@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

May 10 '06 #4
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.

May 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by BJ Freeman | last post: by
6 posts views Thread by magix | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.