|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to override DropDownList.SelectedValue propertyi have a control that inherits from dropdownlist: using System; using System.Web.UI.WebControls; namespace RDK.WebControls { public class SelectedValueDropDown : DropDownList { protected override void OnInit(EventArgs E) { this.Items.Add(new ListItem("NONE", "NONE")); } public override string SelectedValue { get { return this.SelectedValue; } set { try { this.SelectedValue = value; } catch { this.SelectedValue = "Error"; } } } } } when i try to set the selectedvalue i get a server application unavailable error page <%@ Page %> <script runat="server"> void Page_Load(Object Sender, EventArgs E) { ddlWhich.SelectedValue = "ME"; } </script> <html> <head> <title>Drop Down</title> </head> <body> <form id="frm" runat="server"> <RDK:SelectedValueDropDown id="ddlWhich" runat="server" /> </form> </body> </html> how am i supposed to override/use the selectedvalue property You should use the keyword "base" instead of "this" in a derived class method
to access the overridden method in the base class, e.g. base.SelectedValue = value; otherwise you caused an infinite loop. BTW, the logic you have in the SelectedValue does not make sense (the list does not have a value named "Error" in it yet you are trying to set it when trapping an error) Show quoteHide quote "Abraham Andres Luna" wrote: > hey everyone, > > i have a control that inherits from dropdownlist: > > using System; > using System.Web.UI.WebControls; > > namespace RDK.WebControls > { > public class SelectedValueDropDown : DropDownList > { > protected override void OnInit(EventArgs E) > { > this.Items.Add(new ListItem("NONE", "NONE")); > } > > public override string SelectedValue > { > get > { > return this.SelectedValue; > } > set > { > try > { > this.SelectedValue = value; > } > catch > { > this.SelectedValue = "Error"; > } > } > } > } > } > > > when i try to set the selectedvalue i get a server application unavailable > error page > > <%@ Page %> > <script runat="server"> > void Page_Load(Object Sender, EventArgs E) > { > ddlWhich.SelectedValue = "ME"; > } > </script> > <html> > <head> > <title>Drop Down</title> > </head> > <body> > <form id="frm" runat="server"> > <RDK:SelectedValueDropDown id="ddlWhich" runat="server" /> > </form> > </body> > </html> > > > how am i supposed to override/use the selectedvalue property > > > yeah i was setting it to a non-existent value to make sure the trycatch
works thank you for your answer Show quoteHide quote "Phillip Williams" <Phillip.Willi***@webswapp.com> wrote in message news:0C1896C5-9F3F-4313-B71C-EFDE33635FC5@microsoft.com... > You should use the keyword "base" instead of "this" in a derived class > method > to access the overridden method in the base class, e.g. base.SelectedValue > = > value; otherwise you caused an infinite loop. > > BTW, the logic you have in the SelectedValue does not make sense (the list > does not have a value named "Error" in it yet you are trying to set it > when > trapping an error) > > -- > HTH, > Phillip Williams > http://www.societopia.net > http://www.webswapp.com > > > "Abraham Andres Luna" wrote: > >> hey everyone, >> >> i have a control that inherits from dropdownlist: >> >> using System; >> using System.Web.UI.WebControls; >> >> namespace RDK.WebControls >> { >> public class SelectedValueDropDown : DropDownList >> { >> protected override void OnInit(EventArgs E) >> { >> this.Items.Add(new ListItem("NONE", "NONE")); >> } >> >> public override string SelectedValue >> { >> get >> { >> return this.SelectedValue; >> } >> set >> { >> try >> { >> this.SelectedValue = value; >> } >> catch >> { >> this.SelectedValue = "Error"; >> } >> } >> } >> } >> } >> >> >> when i try to set the selectedvalue i get a server application >> unavailable >> error page >> >> <%@ Page %> >> <script runat="server"> >> void Page_Load(Object Sender, EventArgs E) >> { >> ddlWhich.SelectedValue = "ME"; >> } >> </script> >> <html> >> <head> >> <title>Drop Down</title> >> </head> >> <body> >> <form id="frm" runat="server"> >> <RDK:SelectedValueDropDown id="ddlWhich" runat="server" /> >> </form> >> </body> >> </html> >> >> >> how am i supposed to override/use the selectedvalue property >> >> >>
Finding a way to bind ASP.NET controls(two way) to a typed-dataset
Datagrid paging I lose my sort Postback in Web Controls client-side .NET control Coloring Calendar !!! Status text Combining 2 Fields Using ListBox.DataTextField DropDownList LoadControl and Multiple IDs in UserControls Error FormView DataBinding in Insert mode |
|||||||||||||||||||||||