Design Time support for custom ASP.Net controls

Discussion in 'ASP .Net' started by onyxring, Feb 15, 2006.

  1. onyxring

    onyxring Guest

    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;
    }
    }
    }
     
    onyxring, Feb 15, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2ltb24=?=

    Custom Control - Design Time Support

    =?Utf-8?B?U2ltb24=?=, Jan 24, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    334
    =?Utf-8?B?U2ltb24=?=
    Jan 24, 2007
  2. Mark Olbert
    Replies:
    1
    Views:
    520
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 17, 2007
  3. David Keenan

    Custom collection design time support

    David Keenan, Oct 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    159
    David Keenan
    Oct 13, 2003
  4. MLibby

    Web Custom Control - Design Time Support ? ? ?

    MLibby, Sep 3, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    156
    MLibby
    Sep 4, 2004
  5. Darren Clark

    Design Time Support for custom User Controls

    Darren Clark, Jan 13, 2006, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    191
    Darren Clark
    Feb 15, 2006
Loading...

Share This Page