locked
Container or MasterPage for ASCX Control? RRS feed

  • Question

  • User1678673908 posted

    Hi,

    I'm having lots of custom ASP .NET controls on my page. I'd like to in some way to surround them with a container that I have made, its actually just a frame with a shadow. Kind of like using a master page for a control... In the example below, the text is just an ASCX control, surrounded by a graphical container that can be easily re-used for all my controls without duplicating to much code...

     Anyone got any ideas?

     ASP Control Container

    Thanks/Jesper

    Friday, July 4, 2008 8:24 AM

Answers

  • User481221548 posted

    Hi Jesper

    I would make an additional Control for this Work, so you don`t have to refactor any Control that should have that visual appear.
    That Control can be an Panel like one, or one with (optionally) templates and / or Properties to configure the appearance.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 6, 2008 6:49 PM
  • User481221548 posted

    Hi Jesper

    I surely understood exactly what you said :-)
    A Panel like Control is very easy to implement, do something like this:

        [ParseChildren(false)]
        public class PanelTest : WebControl
        {
            public PanelTest() : base(HtmlTextWriterTag.Div) { }
        }

    And then you can override the Render Method, render something (maybe a template too) before "base.Render()" and something after.

    Inform you about Temlates, Keywords are: ITemplate, PersistenceMode, ...

    HTH

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2008 3:57 PM

All replies

  • User-125547262 posted

    One option convert your graphical container into a custom  templated control with a content template and embed your controls in side it


    Friday, July 4, 2008 9:10 AM
  • User-16411453 posted

     Redesign your control to be the graphical Image and a panel container, and set the text as a property defined by the user in design mode.

    Friday, July 4, 2008 4:03 PM
  • User481221548 posted

    Hi Jesper

    I would make an additional Control for this Work, so you don`t have to refactor any Control that should have that visual appear.
    That Control can be an Panel like one, or one with (optionally) templates and / or Properties to configure the appearance.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 6, 2008 6:49 PM
  • User1678673908 posted

    Hi,

    I have been looking around for information about templates and such, but did not find any satisfying examples. I will give an example of what I'm trying to achieve... 

     Somehow I'd like to define for instance a table with a content pane inside it which will be my template/container.

    <div>
    <
    table background="fancy_background.jpg"><tr><td>
    <
    content id="controlContainer">

    <!-- MY CONTROL SHOULD BE PLACED HERE -->

    </content>
    </
    td></tr></table>
    </div>

    The content pane will be filled with anyone of my CustomControls that in some way inherit this container template ie. like a masterpage (not applicable on controls though) or most of the CMS systems out there...

    Please help me! I need to be pointed in the right direction. Didn't find any sites with good examples...

    /Jesper

    Tuesday, July 8, 2008 10:26 AM
  • User481221548 posted

    Hi Jesper

    I surely understood exactly what you said :-)
    A Panel like Control is very easy to implement, do something like this:

        [ParseChildren(false)]
        public class PanelTest : WebControl
        {
            public PanelTest() : base(HtmlTextWriterTag.Div) { }
        }

    And then you can override the Render Method, render something (maybe a template too) before "base.Render()" and something after.

    Inform you about Temlates, Keywords are: ITemplate, PersistenceMode, ...

    HTH

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2008 3:57 PM
  • User1678673908 posted

     Thanks... This helped... I'm now able to generate HTML before and after my custom tag by enclosing it in my Custom Container Control. When using HTMLTextWriter the simplies way for me would be to just write the line exactly as I read them from the HTML file, but this results in the writer actually writing out the tags on the page instead of treating them as HTML. Is there a way to get it to interpret the HTML code as code and not text? Otherwise I guess i could read the HTML file as XML and use the HTMLTextWriter writefullbegintag/writefullendtag etcetera... But this would be to overdo it i feel...

     Thanx for any hints...

    [co] Template HTML Container file

    <table border="1" style="backgroundcolor: red;">
      <tr>
        <td>
          [xlsModuleContent]
        </td>
      </tr>
    </table>

    ------------------------------------------

    [co] ASPX File

    <%@ Register src="Test.ascx" TagName="Test" TagPrefix="uc1" %>

    <uc1:Test ID="Test1" runat="server">
    <xlsTools:uglyCalendar ID="PrettyContainer1" runat="server"></xlsTools:uglyCalendar>
    </uc1:Test>

    ------------------------------------------

    [co] Using INamingContainer

     <ParseChildren(False)> _
    Partial Public Class Test
        Inherits System.Web.UI.UserControl
        Implements INamingContainer

    ---------------------------------------------------

    [co] Looping through a list of HTML contents and rendering the inner content of the control at the position where I put the content tag in my HTML.

            For i As Integer = 0 To htmlContents.Count
                If htmlContents(i).Contains("[xlsModuleContent]") Then
                    RenderChildren(output)
                Else
                    output.WriteLine(htmlContents(i))
                End If
            Next

    Friday, July 11, 2008 4:40 AM