Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Custom web control string

Reply
Thread Tools

Custom web control string

 
 
shapper
Guest
Posts: n/a
 
      05-10-2007
Hello,

I am creating a custom web control where one of its properties is a
generic list:

<Bindable(True), Category("Format"), DefaultValue(""),
Localizable(True)> Property Features() As Generic.List(Of Feature)
Get
If CStr(ViewState("Features")) Is Nothing Then
Return String.Empty
Else
Return CStr(ViewState("Features"))
End If
End Get
Set(ByVal Value As String)
ViewState("Features") = Value
End Set
End Property ' Features

This is the default way to create a property in a web control, as far
as I know.

I am getting an error saying that string cannot be converted to a
generic list.

How should I create my property?

Thanks,

Miguel

 
Reply With Quote
 
 
 
 
Nico Ploner
Guest
Posts: n/a
 
      05-10-2007
Hi Miguel,

in the DefaultValue attribute you can assign a value to this property when
it is being created. It works in the same way as if you said:
Dim defaultValue as String
myInstance.Features = defaultValue

This code would raise an exception, too.
You should either set the DefaultValue attribute to Nothing or assign some
proper value.

Are you experienced in developing server controls? I'm having trouble with
properties that should be influenced by Themes.
Do you think you could be of help there?

Best Regards,
Nico


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      05-10-2007
Most likely this:
Get
If CStr(ViewState("Features")) Is Nothing Then
Return String.Empty

-- is what's causing it. You've defined the property type as List<Feature>
but your get accessor wants to return String.Empty, which obviously
is a different type than List<Feature>, make sense?

HTH,
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




"shapper" wrote:

> Hello,
>
> I am creating a custom web control where one of its properties is a
> generic list:
>
> <Bindable(True), Category("Format"), DefaultValue(""),
> Localizable(True)> Property Features() As Generic.List(Of Feature)
> Get
> If CStr(ViewState("Features")) Is Nothing Then
> Return String.Empty
> Else
> Return CStr(ViewState("Features"))
> End If
> End Get
> Set(ByVal Value As String)
> ViewState("Features") = Value
> End Set
> End Property ' Features
>
> This is the default way to create a property in a web control, as far
> as I know.
>
> I am getting an error saying that string cannot be converted to a
> generic list.
>
> How should I create my property?
>
> Thanks,
>
> Miguel
>
>

 
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
Custom control within a custom control J R M ASP .Net 2 06-01-2006 06:04 PM
Web user control - custom web control - java script. Leyla ASP .Net Web Controls 0 05-01-2006 10:05 PM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net 1 04-05-2005 01:39 PM
Capturing event from other custom control within another custom control Jonah Olsson ASP .Net Web Controls 2 04-05-2005 12:56 PM
ControlDesigner not invoked on custom control when control is rendered within another custom control Matt Sokol ASP .Net Building Controls 2 08-07-2003 07:13 AM



Advertisments