Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > ViewState don't saved on a custom control

Reply
Thread Tools

ViewState don't saved on a custom control

 
 
lirlir
Guest
Posts: n/a
 
      05-05-2004
Hi to all,

i have this problem:
my sample combine 2 components,

the first one is a simple aspx page (T1.aspx) with a
Button runat server and with the next code:

private void Page_Load(object sender, System.EventArgs e)
{
C1 c = new C1();

this.FindControl("Form1").Controls.Add(c);

}

the second component is a UserControl (C1.ascx) that i create dynamiclly like that:
protected override void Render(HtmlTextWriter writer)
{
TextBox txt = new TextBox();

txt.ID="txtSelectedParams" + UniqueID ;
this.Controls.Add(txt);

base.Render(writer);
}

the problem is that after postback the value on the textbox is gone....

please help me by let me know what am i doing wrong.

lirlir
 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      05-05-2004
Hi,

adding TextBox at Render stage is too late in the Page lifecycle. Postback
data loading occurs first time between Init and Load and second time right
after Load, so if you want to get your TextBox's postback data loaded
automatically, it would need to be added to the Controls collection at Load
(at the latest). However, if you want or need to do it manually, you can
access it via Request.Form collection.

Here's more background information:
http://www.asp.net/Forums/ShowPost.a...&PostID=391019
http://www.asp.net/Forums/ShowPost.a...&PostID=285389

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke





"lirlir" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi to all,
>
> i have this problem:
> my sample combine 2 components,
>
> the first one is a simple aspx page (T1.aspx) with a
> Button runat server and with the next code:
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> C1 c = new C1();
>
> this.FindControl("Form1").Controls.Add(c);
>
> }
>
> the second component is a UserControl (C1.ascx) that i create dynamiclly

like that:
> protected override void Render(HtmlTextWriter writer)
> {
> TextBox txt = new TextBox();
>
> txt.ID="txtSelectedParams" + UniqueID ;
> this.Controls.Add(txt);
>
> base.Render(writer);
> }
>
> the problem is that after postback the value on the textbox is gone....
>
> please help me by let me know what am i doing wrong.
>
> lirlir



 
Reply With Quote
 
 
 
 
lirlir
Guest
Posts: n/a
 
      05-06-2004
Thanks mate ,

the links were grate it solved my problem.

"Teemu Keiski" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hi,
>
> adding TextBox at Render stage is too late in the Page lifecycle. Postback
> data loading occurs first time between Init and Load and second time right
> after Load, so if you want to get your TextBox's postback data loaded
> automatically, it would need to be added to the Controls collection at Load
> (at the latest). However, if you want or need to do it manually, you can
> access it via Request.Form collection.
>
> Here's more background information:
> http://www.asp.net/Forums/ShowPost.a...&PostID=391019
> http://www.asp.net/Forums/ShowPost.a...&PostID=285389
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
>
>
>
>
>
> "lirlir" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > Hi to all,
> >
> > i have this problem:
> > my sample combine 2 components,
> >
> > the first one is a simple aspx page (T1.aspx) with a
> > Button runat server and with the next code:
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > C1 c = new C1();
> >
> > this.FindControl("Form1").Controls.Add(c);
> >
> > }
> >
> > the second component is a UserControl (C1.ascx) that i create dynamiclly

> like that:
> > protected override void Render(HtmlTextWriter writer)
> > {
> > TextBox txt = new TextBox();
> >
> > txt.ID="txtSelectedParams" + UniqueID ;
> > this.Controls.Add(txt);
> >
> > base.Render(writer);
> > }
> >
> > the problem is that after postback the value on the textbox is gone....
> >
> > please help me by let me know what am i doing wrong.
> >
> > lirlir

 
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
Saved Mail Gone and Sent Mail Not Being Saved Gregg Firefox 6 03-06-2006 02:13 AM
asp:label updated via javascript does not get its value saved in the viewstate ibiza ASP .Net 2 02-28-2006 04:51 PM
a class inherited from ArrayList, is saved to ViewState, why the type of the object read from ViewSate is not the class, but the parent, ArrayList leal ting ASP .Net 1 02-10-2004 07:45 PM
Add attributes after viewstate has been saved. Tom Vergote ASP .Net 4 01-29-2004 01:48 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments