tags:

views:

71

answers:

3
+3  A: 

Yes, you're thinking of a UserControl. Extract the relevant HTML out, paste it into a UserControl .ascx template.

Now in your case, you'll probably want the text to be customizable, am I right? So you'll need to replace the <h1> through </p> bit with an ASP.NET label. The resulting .ascx HTML (not counting the @Control directive) will look something like:

<div id="BottomBody">
    <div class="box1024" >
        <div class="content1024">
            <div class="top1024"></div>
            <asp:Label runat="Server" id="label1" />
        </div>
        <div class="bottom1024">
            <div></div>
        </div>
    </div>
</div>

Alternatively, you could do two labels -- one for the header, one for the main text. Or even just have the header be runat="Server" itself.

Next, you'll write a little bit of code in the .ascx code-behind file to expose the label's (or labels', as the case may be) Text property. This would probably look something like:

public string Text
{
    get { return label1.Text; }
    set { label1.Text = value; }
}

If you're in an ASP.NET MVC world, use your Model data instead of a label, and pass in the desired display text string as the model data.

Edit

Addressing the update to the question:

One additional thing to note, the number HTML tags used inside the inner most DIV will change depending on where I use it in my site. So in some cases I will only have 1 tag and 1

tag but in other cases I could have 1 tag, 1

tag, 3 tags, and a HTML table. How can I make that work?

The exact same technique, assuming that the content you're referring to is what's within <div class="content1024">. The Text property of a label can contain any desired arbitrary HTML, and of course you can pass any arbitrary amount of HTML as a string to the Model if you're using MVC.

John Rudy
A: 

(I know I'm going to get in trouble for this from someone)

If its just static content you can just put it in a separate file and INCLUDE it

<!--#INCLUDE VIRTUAL="/_includes/i_yourfile.htm" -->

(File name, extension and location are arbitrary)

Chris Haas
You just opened a can of worms lol. But that wont quite work because he wants content in the middle to be customizable. Or so it seems anyways.
TJMonk15
This was the accepted answer to this question: http://stackoverflow.com/questions/178675/split-large-asp-net-pages-into-pieces/178779#178779 However, note the comment there to beware how ASP.NET may handle such `#include` code. I believe the best practice is to use the in-box UserControl support.
John Rudy
I couldn't quite tell if he wanted dynamic or static content but for the latter this is often the easiest method and avoids the occasional "ambiguous in the namespace" error from user controls. But if you want dynamic content, user controls are definitely the way to go. Also, I have never, ever had a postback problem with INCLUDES, I'd be curious to see what people are doing to get them, maybe master pages.
Chris Haas
+1  A: 

Another left field approach - create a user control but use jQuery to round the corners for you:

<div class="roundcorner">
    <h1>My Header Information</h1>
    <hr />
    <asp:Label runat="Server" id="label1" />
</div>

Issue the following in javascript:

$(document).ready(function(){
   $('div.roundedcorner').corner();
 });

This eliminates all your extra div's and you can still have a user control that you use at will on the server.

David Robbins
+1 for the jQuery idea :)
Gan