0
A
回答
0
更多的研究紧靠这个话题后,我觉得JavaScript解决方案是最好的:
您可以访问使用JavaScript形式的action属性。
<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的一个大风扇......但这并不添加额外的请求到服务器。 如果您认为这有什么缺点,请告诉我。
3
有可能有其他更好/更清洁/正确的方法来做到这一点,例如更换form's action或更改按钮的PostBackUrl,但这是我会做的。
- 重定向到自我搜索词并附加到query string。
- 在页面加载时,如果查询字符串不为空,请执行搜索。
的.aspx:
<asp:Label ID="Label1" runat="server" Text="Search Term: "></asp:Label>
<asp:TextBox ID="txtSearchTerm" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" Text="Search"
onclick="btnSearch_Click" />
的.cs:
+0
我有点不情愿使用Response.Redirect。这不会影响搜索引擎的评价吗? – 2010-10-28 05:04:31
+1
六年后,这篇文章解决了我的问题! :) – 2016-03-26 04:17:54
0
如果你想复制/粘贴URL的能力,你将需要得到搜索参数从表单中重定向到带有URL上的搜索参数的表单,然后读取QueryString值以执行搜索。
0
您还可以使用jQuery做的伎俩,就像这样:
$(function(){
$('input[type="submit"]').click(function(e){
e.preventDefault();
var searchResult = "Search.aspx?q=" + $('input#textbox').val();
$('form#myForm').attr('action',searchResult);
});
});
相关问题
- 1. asp.net webforms routing:可选参数
- 2. ASP.NET中的jqGrid WebForms
- 3. ASP.NET WebForms
- 4. ASP.NET的WebForms FriendlyUrlSegments不包含一个构造函数参数0
- 5. WebForms中的ASP.NET Web API 404
- 6. 在asp.net中的mysql_fetch_array webforms
- 7. webforms asp.net中的区域
- 8. ASP.NET WebForms中的FileUpload formData
- 9. ASP.NET中的URL处理WebForms
- 10. asp.net webforms中的高效gridview
- 11. ASP.NET Webforms中的Foreach RadioButtons
- 12. asp.net认证的WebForms
- 13. ASP.NET Webforms授权
- 14. ASP.NET WebForms规范
- 15. jqTouch with ASP.NET Webforms
- 16. ASP.NET MVC + WebForms
- 17. Asp.net webforms更新
- 18. Asp.net ImageUrl Webforms
- 19. ASP.NET Webforms IHttpModule Singleton
- 20. ASP.NET WebForms确认
- 21. ASP.NET MVC或WebForms?
- 22. jQuery ASP.Net Webforms AJAX
- 23. ASP.NET webforms without javascript
- 24. ASP.NET 4 Webforms Routing
- 25. ServiceStack与ASP.NET WebForms
- 26. 数据集在asp.net中不工作webforms
- 27. ASP.NET WebForms RequiredFieldValidator与中继器
- 28. ASP.net Webforms与ASP.net身份
- 29. 学习Asp.Net WebForms或Asp.Net MVC
- 30. 将ASP.NET MVC混合到ASP.NET WebForms中
你必须提供更多的细节。目前还不清楚“包含搜索页面的表单”的含义。 – egrunin 2010-10-27 14:50:30