473,224 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

loading usercontrol from usercontrol

In my application I have a usercontrol called "base" with a panel
called "pnl1"; in "pnl1" I put my usercontrol.
>From "base" I load another usercontrol called "ctl1".
Now I would like to have 2 possibilities: from "base" to load another
control called "ctl2" (and there's no problem) but I would like also
to load "ctl2" from "ctl1"!
The name of the control to load is "stored" into Session("activeCtl")

base.ascx Page_Load code:

Dim ctl As UserControl = New UserControl

ctl = LoadControl(Session("activeCtl") & ".ascx")
pnl1.Controls.Add(ctl)

The first time my Default.aspx set the value of Session("activeCtl").

ctl1.ascx: code put into a routine that accept a parameter called
"name" with the ascx name to load

Dim pnl1 As Panel

pnl1 = Me.Page.Parent.FindControl("pnl1")

Session("activeCtl") = name
pnl1.Controls.Clear()

Dim ctlChild As UserControl
ctlChild = Me.Page.LoadControl(name & ".ascx")

pnl1.Controls.Add(ctlChild )

also ctl2.ascx has an identical routine.

Then, coming back to explanation.
Application start: "base" is loaded
"base" loads "ctl1"
in "ctl1" there is a button that loads "ctl2"
in "ctl2" there is a button that loads "ctl1"

All seems that works fine... but if I try to click another button
(that execute normal code into control), the event doesn't fire.
Usercontrol is re-loaded another time. If I click another time the
button, the code is executed.

Why????

Sorry for my bad english... is a bit complicated to explain...

davides

Jun 27 '07 #1
2 1571
Hi,

This happens because you do:
1. Controls.Clear
2. Controls.Add
3. You do not assign IDs to your controls

If it happens that on a single postback you clears collection of controls
and then add new controls to this collection, they get auto-IDs different
than they get on the next postback.
Try assigning ID to your dynamically created/loaded controls. Be sure that
you assign the sameID for the same control (as it is for the user).

See http://www.singingeels.com/Articles/...in_ASPNET.aspx
for more details

-yuriy

In my application I have a usercontrol called "base" with a panel
called "pnl1"; in "pnl1" I put my usercontrol.
>From "base" I load another usercontrol called "ctl1".
Now I would like to have 2 possibilities: from "base" to load another
control called "ctl2" (and there's no problem) but I would like also
to load "ctl2" from "ctl1"!
The name of the control to load is "stored" into Session("activeCtl")
base.ascx Page_Load code:

Dim ctl As UserControl = New UserControl

ctl = LoadControl(Session("activeCtl") & ".ascx")
pnl1.Controls.Add(ctl)
The first time my Default.aspx set the value of Session("activeCtl").

ctl1.ascx: code put into a routine that accept a parameter called
"name" with the ascx name to load

Dim pnl1 As Panel

pnl1 = Me.Page.Parent.FindControl("pnl1")

Session("activeCtl") = name
pnl1.Controls.Clear()
Dim ctlChild As UserControl
ctlChild = Me.Page.LoadControl(name & ".ascx")
pnl1.Controls.Add(ctlChild )

also ctl2.ascx has an identical routine.

Then, coming back to explanation.
Application start: "base" is loaded
"base" loads "ctl1"
in "ctl1" there is a button that loads "ctl2"
in "ctl2" there is a button that loads "ctl1"
All seems that works fine... but if I try to click another button
(that execute normal code into control), the event doesn't fire.
Usercontrol is re-loaded another time. If I click another time the
button, the code is executed.

Why????

Sorry for my bad english... is a bit complicated to explain...

davides

Jun 27 '07 #2
On 27 Giu, 17:48, Yuriy Solodkyy <y.dot.solod...@gmail.comwrote:
Hi,

This happens because you do:
1. Controls.Clear
2. Controls.Add
3. You do not assign IDs to your controls

If it happens that on a single postback you clears collection of controls
and then add new controls to this collection, they get auto-IDs different
than they get on the next postback.
Try assigning ID to your dynamically created/loaded controls. Be sure that
you assign the sameID for the same control (as it is for the user).

Seehttp://www.singingeels.com/Articles/Dynamically_Created_Controls_in_A...
for more details

-yuriy

Wonderful!!! This problem makes me crazy for days!!!

Thank you very much.

davides

Jun 28 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
Hi all, I'm having a little problem understanding the concepts of dynamically loading/unloading user conrols: 1. If I have a couple of usercontrols embedded within a few tables cells on my...
1
by: Sundaresan | last post by:
I've a form where I load two user controls dynamically. User Control-1 has a no.of dropdowns and based on the selection I typically populate a datagrid in the user control-2, Also the I could...
2
by: Eric | last post by:
I'm trying to dynamically load a user control using on the .NET framework (not Visual Studio). The control was designed in Visual Studio and is named: Disable.ascx The first line is: <%@...
0
by: Phl | last post by:
Hi, I am trying to create an webform which loads usercontrols dyanamically. I know exactly what to load for some of these controls but for some, I dont want to load it until the user has press a...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
12
by: Joe | last post by:
Hello All: Do I have to use the LoadControl method of the Page to load a UserControl? I have a class which contains three methods (one public and two private). The class acts as a control...
4
by: Tim B | last post by:
Hi, Previously I was loading my .NET Usercontrol like this : <OBJECT id="Obj" classid="Viewer.dll#Viewer.Viewer" width=105 height=20 VIEWASTEXT><param name="DONOTHING" value="1"> </OBJECT> ...
0
by: Mark | last post by:
I am converting a VB6/COM application to VB.NET and must remove all COM objects. VB6/COM App Architecture: Windows Form hosts WebBrowser which loads HTML snippets from local disk. Some of the...
1
by: Nathan Sokalski | last post by:
I am revieving the following error for one of my controls when loading any pages that use it: Server Error in '/exposure/app' Application....
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.