Monday, March 26, 2012

Why Page_Load of my web user control is not get called?

I have a web user control and I want to set a property during its initializaiton. But the page_lode method of the control is not get called when I debug it. Here is my control code:

private int myId = 1;

private void Page_Load(object sender, System.EventArgs e)
{
if (myId == 1)
{
btnTitle.Text = "First button";
}
if (myID == 2)
{
btnTitle.Text = "Second button";
}

}

Don't know why. Did I miss anything here?

Thanks.Look for the InitializeComponent method. (If using VS.NET, it may be hidden due to the outlining feature.)

It should contain:
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
// other code
}

If its missing, add it back. Some versions of VS.NET have a bug that occassionally delete this and other event handlers in this very important setup method.

0 comments:

Post a Comment