By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,501 Members | 2,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,501 IT Pros & Developers. It's quick & easy.

How to load different user control - Call made from control being replaced

P: n/a
I need to replace a user control on a page with a different user control.
The challenge I'm faced with is that this call is being made from the user
control being replaced.

Normally I replace one user control with another user control like this
'Using vb.net 1.1

ctl = LoadControl(ctlPath)
Me.cellControlHolder.Controls.Clear()
Me.cellControlHolder.Controls.Add(ctl)
However, here's the unique scenario I'm working with now: The main (parent)
page is default.aspx and in Me.cellControlHolder (in default.aspx) I've
loaded ShoppingCart.ascx. Now in the shoppingcart control a user clicked on
a the checkout button and in that onclick event I found that the user hasn't
logged in yet. So now I want to replace the shopping cart user control with
the Login.ascx user control. But keep in mind that this code is running in
the shopping cart control. In an nutshell I need to call a method from in
the shoppingcart control to its parent (default.aspx) and this method will
run this:

ctlPath="blablabla/Login.ascx"
ctl = LoadControl(ctlPath)
Me.cellControlHolder.Controls.Clear()
Me.cellControlHolder.Controls.Add(ctl)

Any great ideas on how to do this?

--
mo*******@nospam.com
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This trick has a pretty good success rate. If I can't figure out something
even if my life depened on it, post a question to the user groups and it
will automaticly come to my mind. I figured it out and here' how:
'Note: this code is running in the shoppingcart user control and is located
in a table cell called "cellControlHolder"on the default page.
Dim ctlHolder As Control
Dim ctl As UserControl

Dim ctlPath As String = "Login.ascx"
ctlHolder = Me.Parent ' me.parent is "cellControlHolder"

ctl = LoadControl(ctlPath)
ctlHolder.Controls.Clear()
ctlHolder.Controls.Add(ctl)

--
mo*******@nospam.com
"moondaddy" <mo*******@nospam.com> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
I need to replace a user control on a page with a different user control.
The challenge I'm faced with is that this call is being made from the user
control being replaced.

Normally I replace one user control with another user control like this
'Using vb.net 1.1

ctl = LoadControl(ctlPath)
Me.cellControlHolder.Controls.Clear()
Me.cellControlHolder.Controls.Add(ctl)
However, here's the unique scenario I'm working with now: The main (parent) page is default.aspx and in Me.cellControlHolder (in default.aspx) I've
loaded ShoppingCart.ascx. Now in the shoppingcart control a user clicked on a the checkout button and in that onclick event I found that the user hasn't logged in yet. So now I want to replace the shopping cart user control with the Login.ascx user control. But keep in mind that this code is running in the shopping cart control. In an nutshell I need to call a method from in
the shoppingcart control to its parent (default.aspx) and this method will
run this:

ctlPath="blablabla/Login.ascx"
ctl = LoadControl(ctlPath)
Me.cellControlHolder.Controls.Clear()
Me.cellControlHolder.Controls.Add(ctl)

Any great ideas on how to do this?

--
mo*******@nospam.com

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.