I actually figured out the problem if this helps anybody else. When I
was loading the ascx file on the aspx page using LoadControl(), I was
doing this from the Page_Load area. If the web user control is loaded
in the OnInit area, there is no problem on postbacks.
On Feb 29, 4:56 pm, Phil H <goo...@philphall.me.uk> wrote:
> On 28 Feb, 20:08, "beno...@gmail.com" <beno...@gmail.com> wrote:
>
>
>
> > 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.ascxcontains 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 apostback, 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 thepostbackis still
> > visible on the screen afterwards. So I don't believe it's a problem
> > with theViewState, 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 thepostbackin the
> > Page_Load area. The control is found, but the Text parameter is
> > always blank.
>
> > Very strange. Any ideas?
>
> Hi
>
> ViewStateonly preserves the visible content of controls (e.g. Text in
> a textbox) even when they are created programmatically so long as the
> code used to construct them is re-executed onpostback(the pageViewStatedata is then re-linked to the originating control). Any
> other type of data created programatically but varies between
> postbacks will be lost. Use Session states instead.
|