Reputation: 1007
I would like to know how to create an ASP.NET user control that allows for inner content (and how to render the inner content.
As a very simple example, let's say we're creating a control to create a div, so the control would be used as follows:
<%@ Page Language="C#" %>
<%@ Register TagPrefix="custom" TagName="MyDiv"
Src="~\Controls\MyDiv.ascx" %>
<html>
<head />
<body>
<custom:MyDiv id="Div1" runat="server">
... customizable content here ...
</custom:MyDiv>
</body>
<html>
The control should be agnostic to its inner content - i.e. any asp.net content can be added and will be rendered as per usual, and then surrounded with <div>
and </div>
tags.
(Note: I'm obviously not trying to make a control to simulate div tags, it's just a simple example.)
Upvotes: 0
Views: 249
Reputation: 3289
It's an interesting question. Before I suggest an answer, I think you should look into Master Pages: http://www.asp.net/web-forms/tutorials/master-pages
If that doesn't provide your solution, and you want to stick with the User Control route, it won't work the way you want to do it.
Upvotes: 1