问题描述
我有一个应用程序,我目前正在开发一个搜索表单,我想它是方法的当量=GET
。
I have a search form in an app I'm currently developing, and I would like for it to be the equivalent of method="GET"
.
因此,点击搜索按钮时,用户进入 search.aspx?Q = +在+查询+他进入
Thus, when clicking the search button, the user goes to search.aspx?q=the+query+he+entered
我想这个原因很简单,可收藏的URL,再加上感觉清洁剂做这种方式。
The reason I want this is simply bookmarkable URLs, plus it feels cleaner to do it this way.
我也不想附加到URL或者视图状态隐藏字段的值。
I also don't want the viewstate hidden field value appended to the URL either.
最好的我能想出的是这样的:
The best I could come up with for this is:
- 捕获按钮的服务器端Click事件和
的Response.Redirect
。 - 附加一个Javascript
的onclick
处理程序来触发该按钮window.location.replace
。
- Capture the server-side click event of the button and
Response.Redirect
. - Attach a Javascript
onclick
handler to the button that fires awindow.location.replace
.
双方感到离奇和次优...
你能想出更好的方法呢?
Both feel quirky and sub-optimal...Can you think of a better approach?
推荐答案
使用一个普通的旧的HTML形式,而不是一个服务器端的形式(RUNAT =服务器),而你的确应该能够使它发挥作用。
Use a plain old html form, not a server side form (runat=server), and you should indeed be able to make it work.
这可能不过是一个问题,如果你有一个外面包裹整个页面在服务器端表单框视觉工作室母版页的,因为你不能嵌套形式。
This could however be a problem if you have an out of the box visual studio master page which wraps the entire page in a server side form, because you can't nest forms.
Web表单没有吸,但默认实现经常做。你不必使用Web表单的一切。有时,普通的旧后/获取和处理请求code会做就好了。
Web forms don't have to suck, but the default implementations often do. You don't have to use web forms for everything. Sometimes plain old post/get and process request code will do just fine.
这篇关于我该怎么办<形式方法="获得">在ASP.Net的搜索表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!