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


    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?


    Joey Lee, Jun 30, 2005
    1. Advertisements

  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");

    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
    1. Advertisements

  3. Joey Lee

    Joey Lee Guest

    Joey Lee, Jul 1, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.