SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP.net form submission and getting values

    Hi,

    I am new to ASP.net.

    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.
    HTML Code:
     <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:DropDownList>
    
                                    <asp:Button ID="Button1" runat="server" PostBackUrl="~/search-results.aspx" CssClass="Button" Text="Submit" Font-Size="7pt" Height="20px" />  
    </form>
    On search-results.aspx page I try to get the values using:
    HTML Code:
    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.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,112
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,876
    Mentioned
    46 Post(s)
    Tagged
    0 Thread(s)
    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"];


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •