我们需要从库中的函数订阅下一页加载事件
问题是订阅工作的唯一地方是如果我们在 Page.OnInit 中这样做:
override protected void OnInit(EventArgs e)
{
if (!IsPostBack){
this.Load += test; //this would work only the first time if you want the test function to be called in each pageload you have to remove the !ispostback condition
}
protected void test(object sender, EventArgs e)
{//enters correctly
}
我们想要的是这样的:
In website proyect:
buttonDoSomething_Click(object sender, EventArgs e)
{
Functions.CheckNextPageLoad(this);
}
In function library proyect:
CheckNextPageLoad(Page pagex)
{
pagex.Load+=CheckNextPageLoadEvent;
}
CheckNextPageLoadEvent(object sender, EventArgs e)
{
Page page = HttpContext.Current.Handler as Page; //or get it from the sender object
//check especific property of the postback or change something especific
}
这将有助于作为我们相关问题的替代解决方案(所以 2x1): ASP.NET c# Fix for the OK event of a custom ConfirmMessagebox inside a function library (Getting the button clicked on the postback/next pageload we can call委托方法)