开发者

Form and QueryStrings in ASP.Net

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>N开发者_Python百科arrow 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?


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.


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.


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜