User Controls Dynamically Loaded and Nested

G

Guadala Harry

I have this scenario:
ASPX Page dynamically loads userControl1 - which in turn dynamically loads
userControl2. UserControl2 contains a TextBox Web Server control.

When a user clicks a [save now] button in the ASPX page (not in either user
control), a Postback occurs during which I'd like to retrieve the Text
property value of the TextBox control. I have plenty of examples to work
from that show how to retrieve a property value of a user control from the
hosting aspx page's code behind. But those examples don't account for the
user controls being nested and dynamically loaded. Is what I'm attempting to
do possible? Any guidance would be greatly appreciated. None of my samples
or books that describe programmatically manipulating user controls seem to
deal with nested and dynamically loaded controls, and my knowledge of the
ASP.NET request processing internals is a bit limited.

Thanks!
 
M

Marina

You could probably get it from the Form collection. However, it would mean
you would have to know the id of the textbox that was generated by asp.net
taking into account the nesting of the controls, etc.
 
G

Guadala Harry

Ah yes - the good ole Form collection - can always go to that as a last
resort.




Marina said:
You could probably get it from the Form collection. However, it would mean
you would have to know the id of the textbox that was generated by asp.net
taking into account the nesting of the controls, etc.

Guadala Harry said:
I have this scenario:
ASPX Page dynamically loads userControl1 - which in turn dynamically loads
userControl2. UserControl2 contains a TextBox Web Server control.

When a user clicks a [save now] button in the ASPX page (not in either user
control), a Postback occurs during which I'd like to retrieve the Text
property value of the TextBox control. I have plenty of examples to work
from that show how to retrieve a property value of a user control from the
hosting aspx page's code behind. But those examples don't account for the
user controls being nested and dynamically loaded. Is what I'm
attempting
to
do possible? Any guidance would be greatly appreciated. None of my samples
or books that describe programmatically manipulating user controls seem to
deal with nested and dynamically loaded controls, and my knowledge of the
ASP.NET request processing internals is a bit limited.

Thanks!
 
J

John Saunders

Guadala Harry said:
I have this scenario:
ASPX Page dynamically loads userControl1 - which in turn dynamically loads
userControl2. UserControl2 contains a TextBox Web Server control.

When a user clicks a [save now] button in the ASPX page (not in either user
control), a Postback occurs during which I'd like to retrieve the Text
property value of the TextBox control. I have plenty of examples to work
from that show how to retrieve a property value of a user control from the
hosting aspx page's code behind. But those examples don't account for the
user controls being nested and dynamically loaded. Is what I'm attempting to
do possible? Any guidance would be greatly appreciated. None of my samples
or books that describe programmatically manipulating user controls seem to
deal with nested and dynamically loaded controls, and my knowledge of the
ASP.NET request processing internals is a bit limited.

Use delegation. The outer user control can have a TextBoxValue property
which does nothing other than call the inner user control's TextBoxValue
property:

OuterMost:

public string TextBoxValue
{
get {return inner.TextBoxValue;}
set {inner.TextBoxValue = value;}
}

Inner:
public string TextBoxValue
{
get {return innermost.TextBoxValue;}
set {innermost.TextBoxValue = value;}
}

InnerMost:
public string TextBoxValue
{
get {return txtTextBox.Text;}
set {txtTextBox.Text = value;}
}
 

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

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top