PreRender event not firing on UserControl with 2.0 framework

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey I've got an odd problem here.

I have two user controls on a single page. Here is the flow of my page
Page(OnLoad)
UC1(OnPreRender)
UC2(OnPreRender)

Page(ButtonClick)
UC1(OnPreRender)
UC2....NOTHING

Page
protected void btnLogin_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
//handle login
DoSomething();
}


HeaderUserControl
protected override void OnPreRender(EventArgs e)
{
if (!IsPostBack)
{
// Put user code to initialize the page here
SetSomeAttributes();
}

base.OnPreRender(e);
}



ErrorUserControl
protected override void OnPreRender(EventArgs e)
{
DoSomeMoreStuff();
base.OnPreRender(e);
}


The OnPreRender event gets fired when the page first loads, but when I click
my Login button the OnClick gets fired, the OnPreRender of my HeaderControl
gets fired, but the OnPreRender of my second ErrorControl gets skipped.

Am I missing something here??

Thanks in advance,

John Scott.
 
I guess I should clarify a little bit more...I was just illustrating which
events do get fired. When debugging I put break points on the page_load,
uc1_prerender and uc2_prerender

When the page loads all events fire properly.
When I click on an image button the page posts back and the page_load event
fires, the uc1_prerender event fires, but the uc2_prerender event DOES NOT
fire and I don't know why.

Does that help??
 
The control's PreRender event (OnPreRender method) is not fired in two
cases: when control has an adaptor or when it's invisible. Maybe you
had made ErrorUserControl invisible during the first call to
OnPreRender and because this state was preserved in the ViewState the
OnPreRender after postback was not called.

Regards,
art
 
Back
Top