Calling a function before Page_Load

asp.net, c#

Solution

The easiest way to do this would be to use a HTML Submit button and check to see if it is in the Form on every postback in Page_Init

public void Page_Init(object o, EventArgs e)
{
     if(!string.IsNullOrEmpty(Request.Form["MyButtonName"]))
     {
          A();
     }
}

And in your ASP.NET code:

<Button Type="Submit" Name="MyButtonName" Value="Press Here To Do Stuff Early!" />

I think that will work.

Problem

I have a button that calls function A() When I click on it I want the calls to be made in that order: ``` A() Page_Load() ``` Right now it's doing: ``` Page_Load() A() ``` Is there a way around that or is it just by design and there's nothing I can do about it?

Original source