如何在Page.IsPostBack之前运行事件处理程序

问题描述 投票:0回答:1

我想在按钮事件处理程序中运行代码,但if(Page.IsPostBack)条件首先运行并包含重定向,因此事件永远不会运行。

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
    {
        (do some stuff with save button pressed...)

        // then return the same page to prevent another post on refresh 
        Response.Redirect(Request.Url.AbsoluteUri);
    }
}

在该页面上还有另一个调用处理程序的按钮:

protected void Export_Click(object sender, EventArgs e)
{ 
    (do other stuff..)
}

有没有办法首先运行处理程序或检查单击了哪个按钮,以便我可以向重定向添加条件?谢谢。

c# asp.net
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.