Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Problem with webcontrol state using PlaceHolder within ASCX file

Reply
Thread Tools

Problem with webcontrol state using PlaceHolder within ASCX file

 
 
benoitc@gmail.com
Guest
Posts: n/a
 
      02-28-2008
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?
 
Reply With Quote
 
 
 
 
Phil H
Guest
Posts: n/a
 
      02-29-2008
On 28 Feb, 20:08, "(E-Mail Removed)" <(E-Mail Removed)> 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.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?


Hi

ViewState only 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 on postback (the page
ViewState data 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.
 
Reply With Quote
 
 
 
 
benoitc@gmail.com
Guest
Posts: n/a
 
      03-07-2008
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 <(E-Mail Removed)> wrote:
> On 28 Feb, 20:08, "(E-Mail Removed)" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
loading ascx control dynamically in placeholder Bert ASP .Net 3 12-12-2006 02:34 AM
Button state on aspx page affected by activity within ascx control? KatB ASP .Net 0 06-14-2005 08:08 PM
TabStrip/Multipage using UserControl (.ascx) contained within a UserControl(.ascx) shaileenpatel@yahoo.com ASP .Net Web Controls 2 05-03-2005 05:01 PM
Build control in a placeholder or like a placeholder nail ASP .Net Building Controls 0 09-10-2004 07:57 PM
[ASCX] Add an ascx in a webcontrol... Quentin ASP .Net 1 07-29-2003 07:37 PM



Advertisments