UrlEncode
ASP.NET 快速入门教程/使用服务器控件/执行页导航(方案 2)里有两段代码不是很清楚。
UrlEncode前面的相关内容为何有点不同呢?
源页面向目标页面发送参数的代码。
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E) {
// Navigate to a new page (passing name as a querystring argument) if
// user has entered a valid name value in the <asp:textbox>
if (Name.Text != "") {
Response.Redirect("Controls_NavigationTarget_cs.aspx?name=" + System.Web.HttpUtility.UrlEncode(Name.Text));
}
else {
Message.Text = "Hey! Please enter your name in the textbox!";
}
}
</script>
目标页面接收参数的代码:
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs e) {
if (!Page.IsPostBack) {
NameLabel.Text = Server.HtmlEncode(Request.QueryString["Name"]);
}
}
</script>
UrlEncode前面的相关内容为何有点不同呢?
源页面向目标页面发送参数的代码。
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E) {
// Navigate to a new page (passing name as a querystring argument) if
// user has entered a valid name value in the <asp:textbox>
if (Name.Text != "") {
Response.Redirect("Controls_NavigationTarget_cs.aspx?name=" + System.Web.HttpUtility.UrlEncode(Name.Text));
}
else {
Message.Text = "Hey! Please enter your name in the textbox!";
}
}
</script>
目标页面接收参数的代码:
<script language="C#" runat="server">
void Page_Load(Object Sender, EventArgs e) {
if (!Page.IsPostBack) {
NameLabel.Text = Server.HtmlEncode(Request.QueryString["Name"]);
}
}
</script>