Request.Form Problem

R

Roshawn Dawson

Hi,

I seem to be having trouble using the Request.Form property. Before explaining what I'm trying to
do, have a look at my html:

<form id="Cart" method="post" action="ShoppingCart.aspx">
<table id="items" cellpadding="0" cellspacing="0">
<caption>Your Shopping Cart</caption>
<thead>
<tr>
<th scope="col"><input type="checkbox" id="allItms" onclick="javascript:checkAll2(this)" /></th>
<th scope="col">Title</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="U175XG760VMHCS" /></td>
<td><a href="Details.aspx?asin=159200878X">Maran Illustrated Mac OS X v.10.4 Tiger</a></td>
<td class="price">$14.99</td>
<td><input type="text" name="U175XG760VMHCS" maxlength="3" value="1" /></td>
<td class="price">$14.99</td>
</tr>
<tr>
<td><input type="checkbox" name="U1YOOYBVTVBOX6" /></td>
<td><a href="Details.aspx?asin=0071436820">Investing in Rental Properties</a></td>
<td class="price">$11.61</td>
<td><input type="text" name="U1YOOYBVTVBOX6" maxlength="3" value="1" /></td>
<td class="price">$11.61</td>
</tr>
<tr>
<td><input type="checkbox" name="UGNFCT3Q1NT2M" /></td>
<td><a href="Details.aspx?asin=0060765313">YOU: The Owner's Manual</a></td>
<td class="price">$15.99</td>
<td><input type="text" name="UGNFCT3Q1NT2M" maxlength="3" value="1" /></td>
<td class="price">$15.99</td>
</tr>
</tbody>
<tfoot>
<tr>
<td id="subttl" colspan="5">Subtotal: $42.59</td>
</tr>
</tfoot>
</table>
<input type="submit" value="Update" />
</form>

OK. According to the html above, each row in the table has two input elements, each having the same
name. That means that for every name attribute in the form I should get two values. Am I right?

If I'm right, then this is what I'm trying to do. I would like to retrieve from each row in the
table 1.) the name of the input elements and 2.) retrieve the value of the second input element.
For example, I'm trying to get "U175XG760VMHCS" (the name of the input elements for row #1) and "1"
(the value of the second input element for row #1)

I've tried my best to get this working in ASP.NET but to no avail. Here's my code (part of it):

Dim i As Integer
Dim sb As New StringBuilder()
For i = 0 To Request.Form("Form1").Length - 1
'test to see if one of the key's values equals "on"
If Request.Form.GetValues(i)(i).ToString = "on" Then 'the checkbox is checked
sb.Append("The name is " & Request.Form.GetKey(i) & " & the value is " & Request.Form.Get(i + 1))
End If
Next

I sure hope that someone can help me with this issue. It seems so simple, yet I can't get it done.
Help, please?!?! :-(

Thanks,
Roshawn
 
B

Bruce Barker

checkbox's only postback if checked and has a value. this means a row with a
checked checkbox with a value will post two values for the same name, but an
uncheck row will only post one.

also the browser does guarantee postback order of values, so you cannot
assume it.

-- bruce (sqlwork.com)
 
R

Roshawn Dawson

Man, I wasn't even aware of the browser issue, and I completely forgot about the fact that an
unchecked checkbox won't be returned in the form collection.

Thanks Bruce
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top