【发布时间】:2015-05-16 20:13:45
【问题描述】:
我有一个输入文本框,当按下按钮时,文本框中的任何内容都应作为查询字符串附加并重定向到另一个 url。但是我需要在重定向发生之前单击该按钮两次。
这是aspx代码
<div class="userInputTextBox" style="margin-left: auto; margin-right: auto; margin-top: 10px;">
<asp:TextBox
placeholder="Enter costumer ID"
ID="TextBoxID1"
runat="server"
AutoPostBack="true"
Columns="80"
Visible="true">
</asp:TextBox>
<asp:Button runat="server" Text="Search" OnClick="Search" />
</div>
使用 Search 方法隐藏代码。
protected void Search(object sender, EventArgs e)
{
Response.Redirect(String.Format("UserDetail.aspx?UserID={0}", Server.HtmlEncode(TextBoxID1.Text)));
}
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
注意 URL 应该有
Server.URLEncode,而不是HtmlEncode。
标签: c# asp.net webforms response.redirect