Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Selected state not maintained on postback

Reply
Thread Tools

Selected state not maintained on postback

 
 
Santel
Guest
Posts: n/a
 
      06-12-2007
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
 
 
 
 
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
Guest
Posts: n/a
 
      06-12-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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);
> }
> }
>


 
Reply With Quote
 
 
 
 
Santel
Guest
Posts: n/a
 
      06-13-2007
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
 
Teemu Keiski
Guest
Posts: n/a
 
      06-13-2007
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Session State not maintained asp.net 2.0 =?Utf-8?B?SXVsaWFu?= ASP .Net 2 03-28-2006 05:42 PM
Listbox containing duplicate items - correct selection not maintained on postback? Adam Clauss ASP .Net 10 09-08-2005 06:59 PM
CheckBoxList values not appearing and State not maintained jmhmaine ASP .Net Web Controls 2 01-21-2005 03:32 AM
CheckBoxList values not appearing and State not maintained when ne jmhmaine ASP .Net Web Controls 0 01-20-2005 04:25 PM
ViewState Not maintained for ListBox updated through Client vilas h via .NET 247 ASP .Net 1 06-05-2004 08:20 PM



Advertisments