CreateChildControls and submit from usercontrol

X

xke

I have a base class which overrides CreateChildControls / Render.
Inside CreateChildControls, based on a public property ShowLinks in
this class, I can include/display a usercontrol (kind of set of links
like a menu)

A form P inherits this base class. I set the property me.ShowLinks =
true on the load event of P.
P contains another usercontrol (C) which has a button on it.

When I first call P, everything renders fine. First it goes on P_Load,
C_Load, BaseClass:CreateChildControls and Render. Depends on ShowLinks
property, the links are properly displayed on the page.

The problem is when I press the button from the C control, it changes
the order, it first go to CreateChildControls, it doesn't have
ShowLinks set at this moment, it goes afterwards to Load and the Links
do not display properly.

How can I fix this issue?

Thanks
 
X

xke

Please ignore my previous chaotic post. Thanks for those who wanted to
help me and please let me know if you you see any problems in the
solution I found.

---------- old one ----------------------
Public Class BasePage
Inherits System.Web.UI.Page

Protected Overrides Sub CreateChildControls()
Try
'creating my page frame
..........................
If IncludeTab Then
'add the toolbar tab menu
Dim ctlMenu As Control =
Me.LoadControl("UserControl/tabMenu.ascx")
ctlMenu.ID = "mTabMenuID"
Me.CenterColumn.Controls.Add(ctlMenu)
End If
'keep creating
..........................
' Continue base implementation.
MyBase.CreateChildControls()
Catch ex As Exception

End Try
End Sub

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
.........
End Sub

---------- solution/workaround ----------------------
Public Class BasePage
Inherits System.Web.UI.Page

Protected Overrides Sub CreateChildControls()
Try
'creating my page frame
..........................
'keep creating
..........................
' Continue base implementation.
MyBase.CreateChildControls()
Catch ex As Exception

End Try
End Sub

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
............. code ..........
If IncludeTab Then
'add the toolbar tab menu
Dim ctl As Control = Me.LoadControl("UserControl/
tabMenu.ascx")
ctl.ID = "mTabMenuID"
Me.CenterColumn.Controls.AddAt(0, ctl)
End If
............. code ..........
End Sub

IncludeTab is a Property

--------------------------------------------------------------

Now I am thinking better not posting, it's not a big deal, I've just
moved the dynamic control inclusion from CreateChildControls into
Render.

What was the problem: CreateChildControls fires after Page_Load ( page
load event) except some cases (a usercontrol in a page contains a
button, click on the button and the order is changed!!!). So, in this
case CreateChildrenControls fires first, and of course Page_Load can't
set some properties inside the BaseClass.

I've spent a day learning the way Microsoft implemented this model and
that there's reasons behind. It didn't help me of course cause it
didnt give me a solution but only reasons why things work the way they
work.

I came with this solution which I hope it's a good one .... pls let me
know if you see anything wrong here.
Thanks,
xke
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top