Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > how to override DropDownList.SelectedValue property

Reply
Thread Tools

how to override DropDownList.SelectedValue property

 
 
Abraham Andres Luna
Guest
Posts: n/a
 
      11-10-2005
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


 
Reply With Quote
 
 
 
 
Phillip Williams
Guest
Posts: n/a
 
      11-10-2005
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
>
>
>

 
Reply With Quote
 
 
 
 
Abraham Andres Luna
Guest
Posts: n/a
 
      11-10-2005
yeah i was setting it to a non-existent value to make sure the trycatch
works
thank you for your answer


"Phillip Williams" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>>
>>
>>



 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Please help override property paulsmith5@hotmail.com ASP .Net 1 12-09-2005 09:50 AM
override a property Robin Becker Python 18 10-22-2005 01:46 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM
Help! How do I hide or override property/category display under webcontrols? lavey ASP .Net Web Controls 3 10-31-2003 07:48 PM



Advertisments