1. I have a blank test page. On the page load, it does this:

UserControl c1 = (UserControl)LoadControl("control1.ascx");

this.Controls.Add(c1);

2. I have control1.ascx.cs On the ascx side: i have this single literal:

<asp:Literal ID="litTest1" runat="server" Text="Hello World" />

On the page load, it does:

UserControl c2 = (UserControl)LoadControl("control2.ascx");

this.Controls.Add(c2);

3. i have control2.ascx.cs On the ascx side: I have the following literal:

<asp:Literal ID="litTest2" runat="server" Text="Hello Universe" />

on the ascx.cs side it has:

public string sTest2 = "Hello Existence";

The literals I added was to ensure that the page calls control1 and control1 is calling control2, which it does. On execution I get to see hello World & Hello universe messages, no problem, but NOW, I am trying to get the variable sTest on control2 inside the page load of control1. I want to be able to set that variable from control1.
is that possible? If so, how?

1. I have a blank test page. On the page load, it does this:

UserControl c1 = (UserControl)LoadControl("control1.ascx");

this.Controls.Add(c1);

2. I have control1.ascx.cs On the ascx side: i have this single literal:

<asp:Literal ID="litTest1" runat="server" Text="Hello World" />

On the page load, it does:

UserControl c2 = (UserControl)LoadControl("control2.ascx");

this.Controls.Add(c2);

3. i have control2.ascx.cs On the ascx side: I have the following literal:

<asp:Literal ID="litTest2" runat="server" Text="Hello Universe" />

on the ascx.cs side it has:

public string sTest2 = "Hello Existence";

The literals I added was to ensure that the page calls control1 and control1 is calling control2, which it does. On execution I get to see hello World & Hello universe messages, no problem, but NOW, I am trying to get the variable sTest on control2 inside the page load of control1. I want to be able to set that variable from control1.
is that possible? If so, how?

Hi bigfan

Use session variable

'to assign value
Session("Control1value") = "yourvalue"

'to retrieve value from session
mytextbox.text = Session("Control1value")

If it helps you, mark as solved!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.