Joh*_*ski 11 asp.net postback postbackurl query-string
我有一个表单有时会链接到一些查询字符串参数.问题是,当我回发表单时,查询字符串参数仍然存在.这不是我设置它的方式的问题,但我只是不喜欢它在那里,并且如果你需要按特定顺序检查输入,可能会发现它是一个问题.
有没有办法以简单,干净的方式清除查询字符串参数?我知道我可以改变按钮上的PostBackURL,但这看起来效率不高.
我想你已经回答了自己的问题.使用PostBackURL属性.
<asp:Button PostBackUrl='<%# Request.ServerVariables["URL"] %>' runat="server" Text="Submit" />
Run Code Online (Sandbox Code Playgroud)
或类似的东西
foreach (Control ctrl in Page.Controls)
{
if (ctrl is Button)
{
((Button)ctrl).PostBackUrl = Request.ServerVariables["URL"];
}
}
Run Code Online (Sandbox Code Playgroud)
把它放在你的页面底部?
<script language="javascript" type="text/javascript">
document.forms[0].action = window.location.pathname;
</script>
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到了同样的问题。
我使用以下代码块解决了它:
private void ClearQueryString()
{
PropertyInfo isreadonly = typeof(System.Collections.Specialized.NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
isreadonly.SetValue(this.Request.QueryString, false, null);
this.Request.QueryString.Remove("Action");
this.Request.QueryString.Remove("param1");
this.Request.QueryString.Remove("paramN");
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
26228 次 |
最近记录: |