473,385 Members | 2,005 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,385 software developers and data experts.

Problems with dynamic LoadControl

Hello,

I have the following problem:

I want to add to my site (test.aspx) one (1) UserControl
(customer.ascx) several times - dynamically with a placeholder. As well
I want to hand off different variables (i.e. Session variable) to the
UserControl.

Example:

Test.aspx:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Session("CustomerLetter") = "A"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))
Session("CustomerLetter") = "B"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))
Session("CustomerLetter") = "F"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))
End Sub
customer.ascx:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
przGetCustomer(Session("CustomerLetter"))
get the customer in a Datalist
End Sub
Now the problem:
If I call test.aspx I get in the UserControl (customer.ascx) 3 times
the customer with the letter "F", and not one with "A", one with "B"
and one with "F".

What do I wrong and what can I do?

Thank you for your help.

Andreas
P.S. I try to hand of the variable with Property (Get, Set), but it
doesn't work also.

Mar 4 '06 #1
5 1674
Hi Andreas,

Your code does load the usercontrol three time

// First load
Session("CustomerLetter") = "A"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))

// Second load
Session("CustomerLetter") = "B"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))

// Third load
Session("CustomerLetter") = "F"
plcHldTest.Controls.Add(LoadControl("customer.ascx "))

I suppose you should use condition to load it:

Select (expression)
Case "A" ' or what ever condition for A
Session("CustomerLetter") = "A"
Case "B" ' or what ever condition for B
Session("CustomerLetter") = "B"
Case "F" ' or what ever condition for F
Session("CustomerLetter") = "F"
End Select
plcHldTest.Controls.Add(LoadControl("customer.ascx "))
HTH

Elton Wang

Mar 5 '06 #2
Hi Elton,

thanks for the answer.

But I want to load the usercontrol in fact three times (with different
customer letters)!

The problem are the first both variables ("A" and "B") which are not
recognized. I get the three usercontrols with the letter "F".

What is wrong?

Andreas

Mar 5 '06 #3
Andreas, would this work?
ctrl = Page.LoadControl("myusercontrol.ascx")
ctrl.ID = "controlA"
pnlContainer.Controls.Add(ctrl)

ctrl = Page.LoadControl("myusercontrol.ascx")
ctrl.ID = "controlB"
pnlContainer.Controls.Add(ctrl)

ctrl = Page.LoadControl("myusercontrol.ascx")
ctrl.ID = "controlF"
pnlContainer.Controls.Add(ctrl)

HTH

Jose

"Andreas" <an************@t-online.de> wrote in message
news:11*********************@i40g2000cwc.googlegro ups.com...
Hi Elton,

thanks for the answer.

But I want to load the usercontrol in fact three times (with different
customer letters)!

The problem are the first both variables ("A" and "B") which are not
recognized. I get the three usercontrols with the letter "F".

What is wrong?

Andreas

Mar 5 '06 #4
Set a breakpoint in code and trace running to see what happens.
"Andreas" wrote:
Hi Elton,

thanks for the answer.

But I want to load the usercontrol in fact three times (with different
customer letters)!

The problem are the first both variables ("A" and "B") which are not
recognized. I get the three usercontrols with the letter "F".

What is wrong?

Andreas

Mar 5 '06 #5
Hello Jose,

no - it's the same effect.

Greetings

Andreas

Mar 6 '06 #6

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

Similar topics

1
by: wASP | last post by:
Hello everyone, I'm wondering if anyone knows of any good documentation on dynamic Loading of ASP.NET User Controls using the LoadControl Method? ( ... or with any other method in general?) ...
3
by: Adie | last post by:
Hi, I wonder if anyone can tell me how to add user controls to a page dynamically? In context: I have a bunch of HTML tables which due to time constraints can't be populated to a database, so I...
3
by: Bryan | last post by:
Hello All, I have a page that dynamically adds one of many usercontrols to a placeholder on the main page based on a parameter passed to the page. Here is my problem. The usercontrol may...
3
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As...
4
by: Tim::.. | last post by:
Can someone please help.... I'm having major issues with a user control I'm tring to create! I an trying to execute a sub called UploadData() from a user control which I managed to do but for...
2
by: Dave A | last post by:
I just don't get this... If I need to dynamically load controls into a web page I simply need to go PlaceHolder1.Controls.Add(new Button()); or similar. However when I need to dynamically...
1
by: Gummy | last post by:
Hello, I am loading several user controls dynamically in OnInit() like this: ucListBoxSelections ucLocation = (ucListBoxSelections)LoadControl("UserControls/ucListBoxSelections.ascx");
2
by: germ | last post by:
I am moving a web application from 1.1 to 2.0 This site builds pages dynamically as : PlaceHolder.Controls.Add(LoadControl("~/Controls/Ctl1.ascx")); Everything is working fine as long as the web...
1
by: David | last post by:
Hi, Further to my earlier post about using dynamic usercontrols (which I have still yet to solve), I have another problem. I am creating the UC in the page by LoadControl. The page itself...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.