ASP.NET Web Form parameters in URL(URL 中的 ASP.NET Web 窗体参数)
问题描述
我有一个 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 窗体参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:URL 中的 ASP.NET Web 窗体参数
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
