我的问题是 Page_load 在页面上的任何按钮单击事件之前触发。假设我想回发到同一页面并在查询字符串中传输一些数据,然后在 page_Load 上读取该数据并根据查询字符串中的值填充 gridview (details.aspx => details.aspx?id=2)。
我该怎么做?谢谢!
最佳答案
private void Page_Load()
{
if (IsPostBack)
{
// DO what you need to do from the postback here.
}
}
更新:
如果您使用重定向到页面,则它不再是回发 (Response.Redirect)。 在这种情况下,我看到的选项在 page_load 中,您检查特定的查询字符串参数并对其执行操作。
if(!String.IsNullOrEmpty(Convert.ToString(Request.QueryString["myQueryParam"])))
{
}
关于c# - 使用查询字符串 ASP.NET 发布到同一页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6747697/