469,613 Members | 1,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

CreateChildControls and submit from usercontrol

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

Mar 2 '07 #1
1 3577
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


On Mar 2, 2:43 pm, "xke" <xke...@gmail.comwrote:
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

Mar 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Alex | last post: by
2 posts views Thread by Jason . | last post: by
3 posts views Thread by Iain | last post: by
1 post views Thread by Michael | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.