1

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?

4 Answers 4

3

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.

Sign up to request clarification or add additional context in comments.

Comments

3

That's because QueryString is for GET requests, not POST. You want to use Request.Form for posted data.

Response.Write(Request.Form["keywords"]); 

Read more documentation for the Request.Form Collection here.

Comments

2

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"];

Comments

1

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"];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.