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