Simple User Control Question

4

42

Hi,

I've run into a block, that I'm almost sure is really simple...but I
can't seem to clue in right now.

I'd like to create a user control that takes input like this:

<mycontrol:panel id=firstpanel photo="mypic.jpg" runat=server>
<h3>Hi there</h3>
<p>This is a test</p>
</mycontrol>

And renders as this:

<table>
<tr>
<td><img src="mypic.jpg"></td>
<td>
<h3>Arbitrary content<h3>
<p>goes here... even possibly other controls</p>
</td>
</tr>
</table>

My control looks like:

<table>
<tr>
<td><img src="<% =photo %>"></td>
<td>
** How to I get the inner stuff here**
<placeholder maybe???>
</td>
</tr>
</table>

with codebehind that curretnly simply declares the photo property.

How do I grab the content between the <mycontrol> and </mycontrol>, so
that I can put it into the placeholder. (Or other technique...)

Thanks!
 
6

620

I don't know how to grab between <mycontrol></mycontrol>, so this may not
answer your question; but out of curiosity, would it work if you create an
attribute to simulate the solution?

<mycontrol:panel id=firstpanel photo="mypic.jpg" innerHTMLBlock="<h3>Hi
there</h3><p>This is a test</p>" runat=server></mycontrol>

<table>
<tr>
<td><img src="<% =photo %>"></td>
<td>
<% =innerHTMLBlock %>
</td>
</tr>
</table>

I've never done such a thing with a user control, I usually work with custom
controls, so I apologize if this doesn't work at all as it is completely
untested!
 
4

42

620 said:
I don't know how to grab between <mycontrol></mycontrol>, so this may not
answer your question; but out of curiosity, would it work if you create an
attribute to simulate the solution?

<mycontrol:panel id=firstpanel photo="mypic.jpg" innerHTMLBlock="<h3>Hi
there</h3><p>This is a test</p>" runat=server></mycontrol>

<table>
<tr>
<td><img src="<% =photo %>"></td>
<td>
<% =innerHTMLBlock %>
</td>
</tr>
</table>


It would work for a pure html block, and I've got it working that way
now. But its ugly... I want to regularly use fairly elaborate "inner
html" so setting it all within an attribute costs me code highlighting,
formatting, ease of reading, and so on.

Its part of an attempt to separate code from content. So the content
writers have it as easy as possible.

Plus, while I haven't tried it, I don't beleive it would work at all if
I used another control within that in that block (e.g. asp:form
asp:textbox, and so on...) and that will be a requirement in the future.
 
6

620

I used another control within that in that block (e.g. asp:form
asp:textbox, and so on...) and that will be a requirement in the future.

Have you considered implementing this as a custom control instead of a user
control?
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top