URL中的ASP.NET Web表单参数 [英] ASP.NET Web Form parameters in URL
问题描述
我有一个ASP.NET页面,其中包含搜索页面的表单.
I have an ASP.NET page that contain a form that search the page.
有什么解决方法可以使搜索文本包含在URL中吗?
Is there any solution so that I can have the search text in the URL?
我想让我的客户复制/粘贴搜索结果URL.
I want to give the posibility to my clients to copy/paste the search results URL.
推荐答案
经过更多研究之后,我认为这个javascript解决方案是最好的:
After more research abut this topic I think that the javascript solution is the best:
您可以使用JavaScript访问表单的ACTION属性.
You can access the ACTION attribute of the form using JavaScript.
<form id="myForm" action="Search.aspx" onsubmit="return setAction();">
<input id="textbox" />
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
function setAction()
{
var myForm = document.getElementById( "myForm" );
var myText = document.getElementById( "textbox" );
if (myForm && myForm.action && myText && myText.value != null )
{
myForm.action = "Search.aspx?q=" + myText.value;
}
return true;
}
</script>
我个人并不是JavaScript的忠实拥护者...但这不会向服务器添加额外的请求.如果您认为这样做有任何弊端,请告诉我.
Personally I am not a big fan of JavaScript ... but this does not add an extra request to the server. If you think that this has any drawbacks please let me know.
这篇关于URL中的ASP.NET Web表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!