Is there any way to allow an Object property to be set in aspx?

G

Guest

I created a server control that inherits from WebControl that has the
following property:

private Object _Value;
public Object Value {
get { return _Value; }
set { _Value = value; }
}

I want to be able to set this property on the aspx as follows:

<my:Control ID="TestControl" Value="SomeValue" runat="server" />

However, I get the following error:

Cannot create an object of type 'System.Object' from its string
representation 'SomeValue' for the 'Value' property.

I have tried going the TypeConverter route and have got it to work with
other types, but I can't seem to get it to work with the plain old object. I
have been able to work around this problem by adding another property called
ValueString, but I would really rather not go that route. What I really want
is for the aspx to just pass its string to my System.Object since that
conversion should be implicit.

Has anyone gotten this to work for System.Object properties.
 
G

Guest

You are right. The only other method I know of is to use the codebehind,
e.g., in the variables declaration section:

protected WebUserControl1 Control1'

Then later while consuming an event or in the page.init:

Control1.PublicPropName = ObjName;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top