HttpRequest.Form

R

Roshawn Dawson

Hi,

I'm having the hardest time trying to understand the proper usage of
forms in ASP.NET.

Alrightie then! I have a form on my ASP.NET page. To be more specific,
this page displays the items in one's shopping cart. Its layout is done
using a Repeater control. With the exception of the Repeater control
and a button, all other controls inside the form are not server controls
(none contain the runat="server" attribute). They are simple html input
elements created in code. Here's a sample of my code (to give you a
better understanding):

<form id="Form1" method="post" runat="server">
<asp:repeater id="Cart" runat="server"><headertemplate>
<table id="items" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th scope="col"><input type="checkbox"
onclick="javascript:checkAll(this);" id="allItms"/></th>
<th scope="col">Title</th>
<th scope="col">Price</th>
<th scope="col">Quantity</th>
<th scope="col">Total</th>
</tr></thead><tbody></headertemplate>
<itemtemplate>
<tr>
<td><input type="checkbox" id="itm"></td>
<td><a href="Details.aspx?isbn=<%# DataBinder.Eval(Container.DataItem,
"ISBN")%>"><%# DataBinder.Eval(Container.DataItem, "Title")%></a></td>
<td class="price"><%# DataBinder.Eval(Container.DataItem, "Price")%></td>
<td><input type="text" value="<%# DataBinder.Eval(Container.DataItem,
"Quantity")%>" id="Qty" /></td>
<td class="price"><%# DataBinder.Eval(Container.DataItem,
"ItemTotal")%></td>
</tr></itemtemplate>
<footertemplate></tbody>
<tfoot>
<tr><td id="subttl" colspan="5">Subtotal: <%# subtotal
%></td></tr></tfoot></table></footertemplate></asp:repeater>
<asp:button enableviewstate="False" runat="server" text="Update"
id="Update"></asp:button>
</form>

Ok. Now the seemingly "big" question: Can I access any of the form's
input elements via HttpRequest.Form (even though they are not server
controls)? If so, can this be done using a code-behind file?

Thanks,
Roshawn
 
B

Ben Strackany

You should be able to, although you'll only have access to basic elements
(name, value).
 
K

Kevin Spencer

Hi Roshawn,

The "id" attribute is for use on the client browser, and is not available
when the form is posted to the server. To access form values via
Page.Request.Form, you need to assign a "name" attribute to the element.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Paranoia is just a state of mind.
 
R

Roshawn Dawson

Hi guys (and gals),

It appears that you can't access any of the form's input elements via
HttpRequest.Form unless they are server controls (have the
runat="server" attribute).


Roshawn
 

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