Selected state not maintained on postback

Discussion in 'ASP .Net Building Controls' started by Santel, Jun 12, 2007.

  1. Santel

    Santel Guest

    Hi,

    I tried to create a custom server control that displays some radio
    buttons and it should postback the page on selecting the items. I
    tried like below code, but on postback, the selected radio button
    state is not maintained. Anyone could tell me what is missing?

    public class WebCustomControl1 : RadioButtonList
    {
    protected override void Render(HtmlTextWriter output)
    {
    this.Items.Add(new ListItem("aaa"));
    this.Items.Add(new ListItem("bbb"));
    this.AutoPostBack = true;

    base.Render(output);
    }
    }
     
    Santel, Jun 12, 2007
    #1
    1. Advertising

  2. Try moving those lines from the Render event to the Init event.

    --
    I hope this helps,
    Steve C. Orr,
    MCSD, MVP, CSM, ASPInsider
    http://SteveOrr.net



    "Santel" <> wrote in message
    news:...
    > Hi,
    >
    > I tried to create a custom server control that displays some radio
    > buttons and it should postback the page on selecting the items. I
    > tried like below code, but on postback, the selected radio button
    > state is not maintained. Anyone could tell me what is missing?
    >
    > public class WebCustomControl1 : RadioButtonList
    > {
    > protected override void Render(HtmlTextWriter output)
    > {
    > this.Items.Add(new ListItem("aaa"));
    > this.Items.Add(new ListItem("bbb"));
    > this.AutoPostBack = true;
    >
    > base.Render(output);
    > }
    > }
    >
     
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider], Jun 12, 2007
    #2
    1. Advertising

  3. Santel

    Santel Guest

    Hi Steve,

    Thanks for the reply. As it is custom control class, I couldn't see
    any Init event there. Could you tell me which one you are telling?
     
    Santel, Jun 13, 2007
    #3
  4. Santel

    Teemu Keiski Guest

    You'd need to wire an event hander for it. Same can be achieved by
    overriding OnInit method in your control.

    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);
    //...
    this.Items.Add(new ListItem("aaa"));
    this.Items.Add(new ListItem("bbb"));
    this.AutoPostBack = true;

    }


    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net



    "Santel" <> wrote in message
    news:...
    > Hi Steve,
    >
    > Thanks for the reply. As it is custom control class, I couldn't see
    > any Init event there. Could you tell me which one you are telling?
    >
     
    Teemu Keiski, Jun 13, 2007
    #4
    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. vilas h via .NET 247
    Replies:
    1
    Views:
    539
    John Saunders
    Jun 5, 2004
  2. Adam Clauss
    Replies:
    10
    Views:
    1,135
    S. Justin Gengo
    Sep 8, 2005
  3. =?Utf-8?B?SXVsaWFu?=

    Session State not maintained asp.net 2.0

    =?Utf-8?B?SXVsaWFu?=, Mar 27, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,090
    =?Utf-8?B?SXVsaWFu?=
    Mar 28, 2006
  4. jmhmaine
    Replies:
    0
    Views:
    297
    jmhmaine
    Jan 20, 2005
  5. jmhmaine
    Replies:
    2
    Views:
    317
    Steven Cheng[MSFT]
    Jan 21, 2005
Loading...

Share This Page