HighTechTalks DotNet Forums  

Selected state not maintained on postback

ASP.net Building Controls microsoft.public.dotnet.framework.aspnet.buildingcontrols


Discuss Selected state not maintained on postback in the ASP.net Building Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Santel
 
Posts: n/a

Default Selected state not maintained on postback - 06-12-2007 , 02:07 AM






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);
}
}


Reply With Quote
  #2  
Old   
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
 
Posts: n/a

Default Re: Selected state not maintained on postback - 06-12-2007 , 02:18 PM






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" <santel_helvis (AT) sify (DOT) com> wrote

Quote:
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);
}
}



Reply With Quote
  #3  
Old   
Santel
 
Posts: n/a

Default Re: Selected state not maintained on postback - 06-13-2007 , 02:14 AM



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?


Reply With Quote
  #4  
Old   
Teemu Keiski
 
Posts: n/a

Default Re: Selected state not maintained on postback - 06-13-2007 , 12:59 PM



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" <santel_helvis (AT) sify (DOT) com> wrote

Quote:
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?




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.