ViewState don't saved on a custom control

Discussion in 'ASP .Net Web Controls' started by lirlir, May 5, 2004.

  1. lirlir

    lirlir Guest

    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
     
    lirlir, May 5, 2004
    #1
    1. Advertising

  2. lirlir

    Teemu Keiski Guest

    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.aspx?tabindex=1&PostID=391019
    http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=285389

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





    "lirlir" <> wrote in message
    news:...
    > 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
     
    Teemu Keiski, May 5, 2004
    #2
    1. Advertising

  3. lirlir

    lirlir Guest

    Thanks mate ,

    the links were grate it solved my problem.

    "Teemu Keiski" <> wrote in message news:<>...
    > 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.aspx?tabindex=1&PostID=391019
    > http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=285389
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    > http://blogs.aspadvice.com/joteke
    >
    >
    >
    >
    >
    > "lirlir" <> wrote in message
    > news:...
    > > 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
     
    lirlir, May 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. leal ting
    Replies:
    1
    Views:
    523
    Bryan Donaldson
    Feb 10, 2004
  2. Tom Vergote
    Replies:
    4
    Views:
    485
    Tom Vergote
    Jan 29, 2004
  3. ibiza
    Replies:
    2
    Views:
    3,998
    ibiza
    Feb 28, 2006
  4. xamman
    Replies:
    1
    Views:
    393
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Feb 10, 2007
  5. Matt Sokol
    Replies:
    2
    Views:
    433
    Theo Tillotson
    Aug 7, 2003
Loading...

Share This Page