Rendering Custom Control during design time

Discussion in 'ASP .Net Building Controls' started by Joey Lee, Jun 30, 2005.

  1. Joey Lee

    Joey Lee Guest

    Hi,

    I have been creating simple custom controls that is able to be added to the
    Visual Studio toolbox and drag & drop to my aspx pages. The main thing i
    need is visual representation during design time.

    In order to do this, i override the render method and insert html codes.

    However I would like to do more by inserting web controls, can this be done?
    Using other ways like user control or overriding the createchildcontrol of
    controls does not allow visual representation design time.

    I was thinking of creating a simple control which have a label and a
    dropdownlist with autopostback. This control is used to control the display
    row for my datagrid. How do i code web controls and allow postback that will
    somehow allow me again to change the display row of my data grid.

    Any ideas or pointer?

    Thanks

    Joey
     
    Joey Lee, Jun 30, 2005
    #1
    1. Advertising

  2. Joey Lee

    Matt Guest

    What worked for me was to create my own Designer class (extending
    System.Web.UI.Design.ControlDesigner). Then you override
    GetDesignTimeHtml() method and in that method you can do stuff like:

    StringWriter sw = new StringWriter();
    HtmlTextWriter tw = new HtmlTextWriter(sw);

    Label lblLink = new Label();
    lblLink.Text = "<";
    lblLink.ForeColor = System.Drawing.Color.Blue;
    lblLink.Style.Add("text-decoration", "underline");
    lblLink.RenderControl(tw);

    If you want to get a reference to the actual control to read a property
    or something:

    MyCustomControl myCC = (MyCustomControl)this.Component;
     
    Matt, Jun 30, 2005
    #2
    1. Advertising

  3. Joey Lee

    Joey Lee Guest

    Hi,

    I had problem making it work from your example. But I manage to find the
    correct resources from your code.

    Thanks :) , without your example I would still be lost

    Here is the url which i found that allow me to manage design time as well as
    use those web controls behind to make things work

    http://msdn.microsoft.com/library/d.../cpconnetframeworkdesign-timearchitecture.asp

    Joey

    "Matt" <> wrote in message
    news:...
    > What worked for me was to create my own Designer class (extending
    > System.Web.UI.Design.ControlDesigner). Then you override
    > GetDesignTimeHtml() method and in that method you can do stuff like:
    >
    > StringWriter sw = new StringWriter();
    > HtmlTextWriter tw = new HtmlTextWriter(sw);
    >
    > Label lblLink = new Label();
    > lblLink.Text = "<";
    > lblLink.ForeColor = System.Drawing.Color.Blue;
    > lblLink.Style.Add("text-decoration", "underline");
    > lblLink.RenderControl(tw);
    >
    > If you want to get a reference to the actual control to read a property
    > or something:
    >
    > MyCustomControl myCC = (MyCustomControl)this.Component;
    >
     
    Joey Lee, Jul 1, 2005
    #3
    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. Barry Carr
    Replies:
    4
    Views:
    805
    Barry Carr
    Jan 15, 2004
  2. Sam Fields

    Rendering DataGrid in a custom control at design time

    Sam Fields, Jan 15, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    157
    Sam Fields
    Jan 15, 2004
  3. HTML
    Replies:
    1
    Views:
    150
    Teemu Keiski
    Jan 28, 2006
  4. Sam Fields

    Rendering DataGrid in a custom control at design time

    Sam Fields, Jan 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    146
    Sam Fields
    Jan 15, 2004
  5. Sam Fields

    Rendering DataGrid in a custom control at design time

    Sam Fields, Jan 15, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    133
    Sam Fields
    Jan 15, 2004
Loading...

Share This Page