Results 1 to 7 of 7

Thread: How to render HTML in between customer user control tags?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    242

    How to render HTML in between customer user control tags?

    Ok,... I've built a custom control. It works fine but I want to extend it to be able to render HTML tags in between the tags. in other words, my control works fine like this:


    <myCustomContol:mycontrol runat="server" />


    but it doesn't work fine when I do this:


    <myCustomContol:mycontrol runat="server">
    <div> Some Html here</div>
    </myCustomContol:mycontrol>


    it gives me this error:

    Parser Error
    Type 'ASP.content_ascx' does not have a property named 'div'.


    I need to make the control able to render HTML content in between the tags. The reason is cause this one control renders ALL the content on the page. However, I want to "sometimes" add extra stuff, and I dont want to have to go into the control to modify it. I want the control to be able to read the HTML in between its tags and render it where I want it to. How can I do this?


    Thanks!

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You might want to add a text property to the control. Then when rendering your control, you will put that text inside your control as a literalcontrol. Just a thought.

  3. #3
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    i might be missing something, but my understanding is that a <DIV> simply defines block level content, and therefore encloses your control and any other text Shouldn't your example read

    Code:
    <div> Some Html here
        <myCustomContol:mycontrol runat="server">label here
        </myCustomContol:mycontrol> 
        and some more text here
    </div>
    ...or something like that

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    all you really need to do is declare yourself a property called div(you may want to name it something else) then output the content of the property in the ascx wherever you want it. when you put tags or attributes in between a web control it acts like a property such as you saying

    mycontrol.div = "blah blah"

    in VB.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    242
    Actually, I figured out a good way to do it. I made a HtmlGenericControl Property in my .ascx file like so:


    private HtmlGenericControl _content;

    public HtmlGenericControl content{
    get{
    return _content;
    }
    set{
    _content = value;
    }
    }


    so when I want to render Html tags I just need to surround it with my content tag:


    <my:control runat="server">
    <content>
    <div>This works</div>
    </content>
    </my:control>


    and in the .ascx file I can get that content like so:

    string contentStr = content.InnerHtml;


    its a cheesy workaround but this way allows me to place that string anywhere I want in the .ascx control

  6. #6
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    not really a cheesy workaround. That is actually pretty much the same thing I was saying.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Posts
    242
    oh,... sorry.,... hehe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width