O
onyxring
I'm reposting this, because I had a bit of difficulty last time and think
that it might have fallen through the cracks. If I'm posting to the wrong
groups, please let me know. Surely someone has some experience with this...
I've been building custom web controls in C# with VS2005. Currently I'm
looking into adding design-time functionality and have reached a point where
I need to generate code in the page the custom control is on. Enter the
CodeDomSerializer class.
I've found several examples creating Designer Serializers, nearly all of
them for windows forms, but a few claiming to work for Web Controls;
however, I have been singularly unsuccessful at every attempt to modify
source code during the design-time experience. Clearly I'm doing something
wrong, but what it is escapes me.
Below is a sample of the technique I've been using, scaled down to the
barest minimum and excluding designers and other things you might expect for
a custom control. It appears to me that this should work, though adding this
"newtest" control to a page clearly does not add the comment expected.
Can anyone add some clarity at to what I'm doing wrong? Thank you in
advance.
-Jim Fisher
/--/begin sample code....
namespace testcontrol {
[DesignerSerializer(typeof(newtest_serializer),
typeof(CodeDomSerializer))]
public partial class newtest : System.Web.UI.WebControls.TextBox {
public newtest() {
InitializeComponent();
}
public newtest(IContainer container) {
container.Add(this);
InitializeComponent();
}
}
internal class newtest_serializer : CodeDomSerializer {
public override object Deserialize(IDesignerSerializationManager
manager, object codeObject) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
return serial.Deserialize(manager,codeObject);
}
public override object Serialize(IDesignerSerializationManager
manager, object value) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
CodeStatementCollection statements =
(CodeStatementCollection)serial.Serialize(manager, value);
statements.Add(new CodeCommentStatement("//--Comment!--"));
return statements;
}
}
}
that it might have fallen through the cracks. If I'm posting to the wrong
groups, please let me know. Surely someone has some experience with this...
I've been building custom web controls in C# with VS2005. Currently I'm
looking into adding design-time functionality and have reached a point where
I need to generate code in the page the custom control is on. Enter the
CodeDomSerializer class.
I've found several examples creating Designer Serializers, nearly all of
them for windows forms, but a few claiming to work for Web Controls;
however, I have been singularly unsuccessful at every attempt to modify
source code during the design-time experience. Clearly I'm doing something
wrong, but what it is escapes me.
Below is a sample of the technique I've been using, scaled down to the
barest minimum and excluding designers and other things you might expect for
a custom control. It appears to me that this should work, though adding this
"newtest" control to a page clearly does not add the comment expected.
Can anyone add some clarity at to what I'm doing wrong? Thank you in
advance.
-Jim Fisher
/--/begin sample code....
namespace testcontrol {
[DesignerSerializer(typeof(newtest_serializer),
typeof(CodeDomSerializer))]
public partial class newtest : System.Web.UI.WebControls.TextBox {
public newtest() {
InitializeComponent();
}
public newtest(IContainer container) {
container.Add(this);
InitializeComponent();
}
}
internal class newtest_serializer : CodeDomSerializer {
public override object Deserialize(IDesignerSerializationManager
manager, object codeObject) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
return serial.Deserialize(manager,codeObject);
}
public override object Serialize(IDesignerSerializationManager
manager, object value) {
CodeDomSerializer serial =
(CodeDomSerializer)manager.GetSerializer(typeof(newtest).BaseType,
typeof(CodeDomSerializer));
CodeStatementCollection statements =
(CodeStatementCollection)serial.Serialize(manager, value);
statements.Add(new CodeCommentStatement("//--Comment!--"));
return statements;
}
}
}