form submission and getting values


I am new to

How do I capture the values of a form which submits to a different page, my code looks something like below:

The form is in default.aspx page and it submits to search-results.aspx page.

 <form id="form1" runat="server">
                       <asp:TextBox ID="txtKeyword" runat="server" CssClass="TextBox" ForeColor="#CCCCCC" MaxLength="150" Width="240px"></asp:TextBox>
                                <asp:DropDownList ID="intSaleRental" runat="server" CssClass="TextBox">
                                    <asp:ListItem Value=0 Selected="True">Property Type</asp:ListItem>
                                    <asp:ListItem Value=1>For Sale</asp:ListItem>
                                    <asp:ListItem Value=2>For Rent</asp:ListItem>

                                <asp:Button ID="Button1" runat="server" PostBackUrl="~/search-results.aspx" CssClass="Button" Text="Submit" Font-Size="7pt" Height="20px" />

On search-results.aspx page I try to get the values using:

string txtKeyword = Request.Form ("txtKeyword");
string intSaleRental= Request.Form ("intSaleRental");

But I get null values.

When I view the source code in browse it shows “c00lt” as prefix of textbox and dropdown listbox names.

Please advice.

Try setting the ClientIDMode on the textbox and the drop down list to Static. That way it should use txtKeyword and intSaleRental as the names of the form fields.

Using ClientIDMode will work yes. But you also need to use square brackets instead of normal braces.

string txtKeyword = Request.Form (“txtKeyword”);
string intSaleRental= Request.Form (“intSaleRental”);

should be:

string txtKeyword = Request.Form[“txtKeyword”];
string intSaleRental= Request.Form[“intSaleRental”];