Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Page_Load vs OnLoad

Why DisplayUsers(); doesn't work?

My base page is:

public class adminPage : System.Web.UI.Page
{
    protected override void OnLoad(EventArgs e)
    {
        if (User.Identity.IsAuthenticated == false) { Response.Redirect("~/Account/login.aspx?ReturnUrl=/admin"); };
        if (!(User.IsInRole("admin") || User.IsInRole("super user"))) { Response.Redirect("/"); };
    }        
  }

my class is

public partial class users : adminPage
{ 
    protected void Page_Load(object sender, EventArgs e)
    {                        
        string sName;
        adminGeneralData.GetToolData(2, out sName);
        pageH1.Text = sName;

        DisplayUsers();
    }

    protected void DisplayUsers()
    {
        DataSet ds = userData.GetUsersData();
        userList.DataSource = ds;
        userList.DataBind();
    }
}

but DisplayUsers() doesn't work,

like image 955
eyalb Avatar asked Mar 19 '11 19:03

eyalb


1 Answers

According to Performance Tips and Tricks in .NET Applications:

Avoid the Autoeventwireup Feature

Instead of relying on autoeventwireup, override the events from Page. For example, instead of writing a Page_Load() method, try overloading the public void OnLoad() method. This allows the run time from having to do a CreateDelegate() for every page.

like image 186
Ryszard Dżegan Avatar answered Oct 18 '22 16:10

Ryszard Dżegan