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