Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   Selected state not maintained on postback (http://www.velocityreviews.com/forums/t758831-selected-state-not-maintained-on-postback.html)

Santel 06-12-2007 06:07 AM

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


Steve C. Orr [MCSD, MVP, CSM, ASP Insider] 06-12-2007 06:18 PM

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" <santel_helvis@sify.com> wrote in message
news:1181628453.582835.193830@z28g2000prd.googlegr oups.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 06-13-2007 06:14 AM

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?


Teemu Keiski 06-13-2007 04:59 PM

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" <santel_helvis@sify.com> wrote in message
news:1181715250.662979.242750@o11g2000prd.googlegr oups.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?
>





All times are GMT. The time now is 09:28 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.