Reputation: 25701
I have a form on home.aspx that is this:
<form name="search" method="post" action="searchresults.aspx" id="searchform" runat="server">
<div class="searchField">
<input name="keywords" type="text" id="keywordSearch" value="Enter keywords" class="watermark" />
</div><!--end searchField-->
<div class="advanceSearchBox">
<p><b>Narrow results by:</b></p>
<asp:Literal ID="ltrlPopulation" runat="server" />
<asp:Literal ID="ltrlDatasource" runat="server" />
</div><!--end advanceSearchBox-->
<div style="float: right; margin-right: 2px;">
<asp:ImageButton ImageUrl="images/go_up.png" AlternateText="GO" Width="34" Height="24" id="keywordSearchGO" runat="server" />
</div>
</form>
And on my searchresults.aspx.cs page I have this QueryString but its always empty:
Response.Write(Request.QueryString["keywords"]);
Did I forget something?
Upvotes: 1
Views: 3884
Reputation: 50825
You could change the opening form tag to:
<form name="search" method="get" action="searchresults.aspx" id="searchform" runat="server">
If you really want to be using query string for some reason.
Upvotes: 3
Reputation: 46047
You're posting to searchresults.aspx, so you will need to access your posted variables through Request.Form or Request.Params.
string keyWords = Request.Form["keywords"];
OR
string keyWords = Request.Params["keywords"];
Upvotes: 1
Reputation: 13676
A post doesn't generate a query string. To access post data, you'll need to do so through the Form or Params property.
Request.Form["keywords"];
Request.Params["keywords"];
Upvotes: 2