DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 11 Jun 2007 23:07:33 -0700,    posted on: microsoft.public.dotnet.framework.aspnet.buildingcontrols        back       

Thread Index
  1    Santel
          2    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
          3    Santel
                 4    Teemu Keiski


Selected state not maintained on postback   
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);
        }
    }
Date:Mon, 11 Jun 2007 23:07:33 -0700   Author:  

Re: Selected state not maintained on postback   
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:1181628453.582835.193830@z28g2000prd.googlegroups.com...

> 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);
>        }
>    }
> 
Date:Tue, 12 Jun 2007 11:18:19 -0700   Author:  

Re: Selected state not maintained on postback   
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?
Date:Tue, 12 Jun 2007 23:14:10 -0700   Author:  

Re: Selected state not maintained on postback   
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:1181715250.662979.242750@o11g2000prd.googlegroups.com...

> 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?
> 
Date:Wed, 13 Jun 2007 19:59:35 +0300   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us