ASP.NET Form Handling

Process of posting data to the server and retrieving values sent.

Retrieve Form Values:

To retrieve the values from a runat server form:

Control

Retrieve value

<asp:textbox id=”txtName” runat=”server” text=””/>

txtName.text

<asp:checkbox id=”cbName” runat=”server” text=”HTML”/>

cbName.text

<asp:dropdownlist id=”ddlName” runat=”server”>
     <asp:listitem value=”1” text=”First”/>
     <asp:listitem value=”2” text=”Second”/>
     <asp:listitem value=”3” text=”Third”/>
</asp:dropdownlist>

ddlName.SelectedItem.Text

or

ddlName.SelectedItem.Value

 

To retrieve form values sent from another page:

Form Type

Retrieve value

<form action=”getvalues.aspx” method=”post”>
  <input type=”text” name=”txtName”>
</form>

Request.Form(“txtName”)

<form action=”getvalues.aspx” method=”get”>
  <input type=”text” name=”txtName”>
</form>       

Request.QueryString(“txtName”)