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

M

moondaddy

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?
 
M

moondaddy

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)
 

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,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top