ASP.NET:在搜索表单的操作页面中读取表单变量值

Shy*_*yju 0 asp.net search form-post

我有一个网站,我想实现搜索功能.所以我添加了下面的代码,在我的HTML页面中有一个搜索框

   <form id="search" method="post" action="Results.aspx">
    <input id="txtSearchKey" type="text" name="txtSearchKey" />
    <input id="Submit1" type="submit" value="submit" /><br />
    <br />
</form>
Run Code Online (Sandbox Code Playgroud)

在Results.aspx中,我想读取用户在txtSearchKey文本框中输入的值.这样做的理想方法是什么?我用了

 string strKey = Request.Form["txtSearchKey"].ToString(); 
Run Code Online (Sandbox Code Playgroud)

但它抛出一个空引用异常.请指教

我不希望在ASP.NET中拥有所有页面.我希望只有结果页面作为ASP.NET

提前致谢

pat*_*ech 5

可能是因为您在文本框字段上没有NAME属性.这是在Request.Form集合中用作键的值.我想,不会提交没有name属性的输入字段.

例如:

<input id="txtSearchKey" type="text" name="txtSearchKey" />
Run Code Online (Sandbox Code Playgroud)