|
-
Mar 30th, 2003, 03:00 AM
#1
Thread Starter
Addicted Member
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!
-
Mar 30th, 2003, 12:34 PM
#2
PowerPoster
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.
-
Mar 31st, 2003, 06:24 AM
#3
Addicted Member
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
-
Mar 31st, 2003, 09:30 AM
#4
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.
-
Mar 31st, 2003, 01:11 PM
#5
Thread Starter
Addicted Member
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
-
Mar 31st, 2003, 02:16 PM
#6
not really a cheesy workaround. That is actually pretty much the same thing I was saying.
-
Apr 1st, 2003, 01:55 AM
#7
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|