[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Selected state not maintained on postback

Santel

6/12/2007 6:08:00 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);
}
}

3 Answers

Steve C. Orr, MCSD

6/12/2007 6:18:00 PM

0

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

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



"Santel" <santel_helvis@sify.com> 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);
> }
> }
>

Santel

6/13/2007 6:14:00 AM

0

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

6/13/2007 5:00:00 PM

0

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....
http://teemu...



"Santel" <santel_helvis@sify.com> 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?
>