Problems with dynamic LoadControl

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.

.


Quantcast