B
benoitc
Hello, I've been trying to solve this problem for a while now, I
wonder if anyone can help. Here is the scenario. Forgive me if it
seems a little convoluted, my organization uses MCMS templates and it
means things can get more complicated in order to work with the
templates.
Form1.aspx -> contains a placeholder (ph1) and nothing else, this is
the page that is viewed in the browser
User1.ascx -> this is loaded into the placeholder on Form1 (ph1)
(using ph1.Controls.Add(Page.LoadControl) )
User1.ascx contains its own placeholder as well (ph2), as well as a
button. It creates a dynamic control (a textbox) within the OnInit()
part of its codebehind, and adds it to the placeholder (ph2) using
ph2.Controls.Add(TextBox1). This takes place in the OnInit() area so
that the dynamic controls are preserved even after postbacks.
When running Form1, if after a postback, you try and capture the value
of the textbox by creating a new object using ph2.FindControl(), it
manages to find the textbox (the FindControl() method does not return
null), but the text parameter is always blank.
The strange thing though, is that when you are viewing the page itself
in the browser, any text that you entered before the postback is still
visible on the screen afterwards. So I don't believe it's a problem
with the ViewState, since the information is actually being preserved
between postbacks. Rather the information seems to be "lost" when you
try to load the textbox using FindControl() after the postback in the
Page_Load area. The control is found, but the Text parameter is
always blank.
Very strange. Any ideas?
wonder if anyone can help. Here is the scenario. Forgive me if it
seems a little convoluted, my organization uses MCMS templates and it
means things can get more complicated in order to work with the
templates.
Form1.aspx -> contains a placeholder (ph1) and nothing else, this is
the page that is viewed in the browser
User1.ascx -> this is loaded into the placeholder on Form1 (ph1)
(using ph1.Controls.Add(Page.LoadControl) )
User1.ascx contains its own placeholder as well (ph2), as well as a
button. It creates a dynamic control (a textbox) within the OnInit()
part of its codebehind, and adds it to the placeholder (ph2) using
ph2.Controls.Add(TextBox1). This takes place in the OnInit() area so
that the dynamic controls are preserved even after postbacks.
When running Form1, if after a postback, you try and capture the value
of the textbox by creating a new object using ph2.FindControl(), it
manages to find the textbox (the FindControl() method does not return
null), but the text parameter is always blank.
The strange thing though, is that when you are viewing the page itself
in the browser, any text that you entered before the postback is still
visible on the screen afterwards. So I don't believe it's a problem
with the ViewState, since the information is actually being preserved
between postbacks. Rather the information seems to be "lost" when you
try to load the textbox using FindControl() after the postback in the
Page_Load area. The control is found, but the Text parameter is
always blank.
Very strange. Any ideas?