Custom attributes/properties at design time (serialization?)

W

WALDO

OK. here's what I want to do.

I have a text editor control that I created. I also have a seriedsof
palette controls that I have created for use with the text editor. The
Idea I want is that the page developer can slap any number of editors
on a webform and any number of palettes on the same webform and
associate an editor with a palette.

So all the editor really needs to know when rendering is the uniqueid
of the selected palette. What I have done is created a property of
type palette on the editor. I have created a typeconverter to grab all
the ids of the palettes on the webform. I have also set the
DesignerSerializationVisibility attribute to Visible and the
PersistenceMode to Attribute. Ultimately what I want to see is this:

<cc1:TextEditor runat="server" id="TextEditor1" Height="200px"
Width="500px" Palette="WebSafePalette1">This is my
InnerContent</cc1:TextEditor>

<cc1:WebSafePalette runat="server"
id="WebSafePalette1"></cc1:WebSafePalette>
<cc1:MSWordPalette runat="server"
id="MSWordPalette1"></cc1:MSWordPalette>
<cc1:StandardPalette runat="server"
id="StandardPalette1"></cc1:StandardPalette>

I want the Id of the selected palette to persist as an attribute
property in the HTML at design-time.

I see the list of palettes in the Palette property of the texteditor.
My problem is that when I set the DesignerSerializationVisibility
attribute to anything other than hidden, I get the error 'Invalid
property value (Object not set to an instance of an object)' whenever
I set the property at design time. When it is set to hidden, I don't
get the error. Unfortunately nothing persists to the texteditor or the
webform.

Any ideas as to how I may accomplish this? I thought maybe my
TypeEditor was wrong. Do I need a custom parser to fish out the
properties? Maybe a custom serializer to put the attribute property
where I want it. Maybe the serializer should put some code in the
InitializeComponent of the webform.
 
W

WALDO

OK. So I figured out my problem partially. It was my typeconverter. I
was assuming that in my ConvertTo function, context and
context.instance would always produce values and therefore was only
converting if they did. It's kind of funny, actually. I always thought
that I would throw some kind of exception if I DIDN'T check those
values. That's irony for you.

So I got the name of the control to persist to my attribute the way I
want. My new problem is how to DEserialize it. When I view the webform
in the browser, it produces the exception:

Unable to generate code for a value of type 'TextEdit.Palette'. This
error occurred while trying to generate the property value for
Palette.

I suppose I understand this. It's trying to generate a palette from
scratch from the value in the attribute, not the reference to the
object.

How would I approach DEserializing this object as a refernce to
another control on the webform?
 

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

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top