您好,当用户单击特定的 LinkButton 时,我需要删除查询字符串。 例如,如果查询字符串是 http://UserProfileManager.com?UserID=1234 ....当用户单击链接按钮时,我希望 url 为 http://UserProfileManager.com 。问题是所有内容都在一页上,我使用 asp:panel 来显示和隐藏网页的不同区域。
任何想法将不胜感激。
最佳答案
您有多种选择:
1) 在后面的代码中,如果查询字符串包含“UserID”键,只需将 LinkButton 的 URL 设置为较短的地址即可:
if (Request.QueryString["UserID"] != null) {
this.LinkButton.PostBackUrl = "http://UserProfileManager.com";
} else {
// other address
}
2) 在隐藏字段中发送 UserID,而不是查询字符串。
3) 将 View 页面和编辑页面分开 - 将所有内容放在一个 *.aspx 中可能会带来更多麻烦,而不是带来任何好处。
关于c# - 从 asp.net 中的 url 中删除查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2957457/