473,734 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add <div> to Body?

I would like to wrap all of the HTML inside of my <body> tag inside a <div> with in my code-behind. I do not want to touch the .aspx page template at all. I know how to make the body tag runat=server and give it an id so I can find it from the code-behind, but after that I want to add the <div>. One problem I see is that I just add the <div> to the <body>, all of the other controls (including the aspx <form>) will not be inside it.

What can I do?

Thanks.
Nov 18 '05 #1
8 4851
I think the panel control wraps the <div> tag. Counldn't you add a panel
control and then add all your webcontrols to the panels control collection.

"localhost" <pr*******@coho rt.ces> wrote in message
news:6D******** *************** ***********@mic rosoft.com...
I would like to wrap all of the HTML inside of my <body> tag inside a <div> with in my code-behind. I do not want to touch the .aspx page
template at all. I know how to make the body tag runat=server and give it
an id so I can find it from the code-behind, but after that I want to add
the <div>. One problem I see is that I just add the <div> to the <body>,
all of the other controls (including the aspx <form>) will not be inside it.
What can I do?

Thanks.

Nov 18 '05 #2
I'm not following you. If you want a div tag in your Page, just put one
there in the Page Template (.sapx). You can put any HTML you want into the
Page Template. And, according to the rules of HTML, and tag or element that
is between the <div> and </div> tags will be inside the div, including form
and all other Controls that render HTML objects in the page.

Offhand, it sounds like you're trying to do something oddly here. What is
the requirement that this div is supposed to fulfill?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:6D******** *************** ***********@mic rosoft.com...
I would like to wrap all of the HTML inside of my <body> tag inside a <div> with in my code-behind. I do not want to touch the .aspx page
template at all. I know how to make the body tag runat=server and give it
an id so I can find it from the code-behind, but after that I want to add
the <div>. One problem I see is that I just add the <div> to the <body>,
all of the other controls (including the aspx <form>) will not be inside it.
What can I do?

Thanks.

Nov 18 '05 #3

I am absolutely not looking to touch the page template at all. I am using program code only to build a page. I don't want to put any HTML in the page template at all because I have custom classes that make modifications to many pages at runtime, and I don't want to hand-edit 223 pages with <div> tags as I go, either. :)

I know that I want to place a the <div> inside the <body>, but then I want to put everything else inside that <div>. That will let me use CSS to define how the page flows overall, letting me handle silly user window maximizes and etc

The following almost works

I make my <div> (it's an HtmlGenericCont rol) called myDiv.
Then I do a Controls.AddAt( pageBody.Contro ls.Count,myDiv) .
Then I do a myDiv.Controls. Add(myForm).
Then I do a pageBody.Contro ls.Remove(myFor m)

For some reason my form controls are now displaying outside of the <div> style area I defined, but that might be a (mis)function of my CSS code. Hmmm..


I'm not following you. If you want a div tag in your Page, just put on
there in the Page Template (.sapx). You can put any HTML you want into th
Page Template. And, according to the rules of HTML, and tag or element tha
is between the <div> and </div> tags will be inside the div, including for
and all other Controls that render HTML objects in the page

Offhand, it sounds like you're trying to do something oddly here. What i
the requirement that this div is supposed to fulfill

--
HTH
Kevin Spence
...Net Develope
Microsoft MV
Big things are made u
of lots of little things

"localhost" <pr*******@coho rt.ces> wrote in messag
news:6D******** *************** ***********@mic rosoft.com..
I would like to wrap all of the HTML inside of my <body> tag inside

<div> with in my code-behind. I do not want to touch the .aspx pag
template at all. I know how to make the body tag runat=server and give i
an id so I can find it from the code-behind, but after that I want to ad
the <div>. One problem I see is that I just add the <div> to the <body>
all of the other controls (including the aspx <form>) will not be inside it
What can I do
Thanks


Nov 18 '05 #4
I can't imagine what sort of CSS you would use on a div which encompasses
everything in the page. You might as well apply a class to the <body> of the
page if that's what you're after. I can certainly agree with and appreciate
the use of divs in the page with classes on each one so that you can use CSS
to position them and work with their styles, but the whole page? And if you
use divs (or ASP.Net Panels) for your content, you dont' need to do anything
outside of the WebForm, as that should encompass the entire contents of the
viewable page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:2D******** *************** ***********@mic rosoft.com...

I am absolutely not looking to touch the page template at all. I am using program code only to build a page. I don't want to put any HTML in the page
template at all because I have custom classes that make modifications to
many pages at runtime, and I don't want to hand-edit 223 pages with <div>
tags as I go, either. :)
I know that I want to place a the <div> inside the <body>, but then I want to put everything else inside that <div>. That will let me use CSS to
define how the page flows overall, letting me handle silly user window
maximizes and etc.
The following almost works:

I make my <div> (it's an HtmlGenericCont rol) called myDiv.
Then I do a Controls.AddAt( pageBody.Contro ls.Count,myDiv) .
Then I do a myDiv.Controls. Add(myForm).
Then I do a pageBody.Contro ls.Remove(myFor m).

For some reason my form controls are now displaying outside of the <div> style area I defined, but that might be a (mis)function of my CSS code.
Hmmm...



I'm not following you. If you want a div tag in your Page, just put one
there in the Page Template (.sapx). You can put any HTML you want into the
Page Template. And, according to the rules of HTML, and tag or element that is between the <div> and </div> tags will be inside the div, including form and all other Controls that render HTML objects in the page.

Offhand, it sounds like you're trying to do something oddly here. What is
the requirement that this div is supposed to fulfill?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:6D******** *************** ***********@mic rosoft.com...
I would like to wrap all of the HTML inside of my <body> tag inside a

<div> with in my code-behind. I do not want to touch the .aspx page
template at all. I know how to make the body tag runat=server and give it
an id so I can find it from the code-behind, but after that I want to add
the <div>. One problem I see is that I just add the <div> to the <body>,
all of the other controls (including the aspx <form>) will not be inside

it.
What can I do?
Thanks.

Nov 18 '05 #5
Hi,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you're dealing with something on Dynamically
constructing a page. The page doesn't have any static template contents,
you'd like to add all the controls dynamicaly in the page class's code.
Also, you want to put a "<div>" tag right inside the "<body>" tag and other
controls(includ ing the server <form> tag) all inside the "<div>" control.
If there is anything I misunderstood, please feel free to let me know.

Based on my research, in an ASP.NET web page, the controls are organized in
a large strucute. And most derived controls(both HtmlControls and ASP.NET
server controls) can use the "Controls" member collection to add sub
controls. Just add them following the right order so that they can be
constructed in the correct structure. So as for the problem in our issue, I
think we can do it as this:
1. use HtmlGenericCont rol object to get the "<body>" tag of the page and
then add a "div" tag as a HtmlGenericCont rol. For example:

Control ctrl = this.FindContro l("myBody");
HtmlControl ctrlDiv = new HtmlGenericCont rol("div");
ctrlDiv.Attribu tes.Add("id","m yDiv");
ctrl.Controls.A dd(ctrlDiv);

2. Since in ASP.NET all the server controls should be placed in a "<form>"
tag whose "runat" is set as "server". So if we use servercontrols, we need
to add a such form tag, just like:
System.Web.UI.H tmlControls.Htm lForm frmMain = new HtmlForm();
frmMain.Attribu tes.Add("id","F orm1");
frmMain.Attribu tes.Add("runat" ,"server");

ctrlDiv.Control s.Add(frmMain);

3. After that, we can place all other controls inside the server "<form>"
tag. Just create their instance and add them into the server form tag
object's Controls collection.
Also, I've build a simple page based on the above steps, you may have a try
if you think necessary.

-------------------------------aspx page
code---------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>DivAdd </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body id="myBody" runat="server"> </body>
</HTML>

----------------------------------code-behind page class
code------------------
public class DivAdd : System.Web.UI.P age
{
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
Control ctrl = this.FindContro l("myBody");
HtmlControl ctrlDiv = new HtmlGenericCont rol("div");
ctrlDiv.Attribu tes.Add("id","m yDiv");
ctrlDiv.Attribu tes.Add("style" ,"POSITION: absolute; BACKGROUND-COLOR:
#66ffff");

System.Web.UI.H tmlControls.Htm lForm frmMain = new HtmlForm();
frmMain.Attribu tes.Add("id","F orm1");
frmMain.Attribu tes.Add("runat" ,"server");

Table tb = new Table();
TableRow tr = new TableRow();

TableCell cellTemp = new TableCell();
Label lblTemp = new Label();
lblTemp.Text = "Name:";
cellTemp.Contro ls.Add(lblTemp) ;
tr.Cells.Add(ce llTemp);

cellTemp = new TableCell();
TextBox txtTemp = new TextBox();
txtTemp.ID = "txtName";
cellTemp.Contro ls.Add(txtTemp) ;
tr.Cells.Add(ce llTemp);

tb.Rows.Add(tr) ;

frmMain.Control s.Add(tb);

ctrlDiv.Control s.Add(frmMain);
ctrl.Controls.A dd(ctrlDiv);

}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}

-------------------------------------------------------------------------

Please check out the preceding suggestion. If you have any question or need
any further help, please feel free to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #6
I agree with Kevin's point - the div doesn't give you any advantage from a
CSS standpoint because anything you do with a div you can do with a body
element. Instead of:
div.mydivclass a { }
use
body a { }

and so on.

You code for adding and removing the form element seemed fine. I just
suggest you do it in a loop - loop over the page's Controls collection and
add and remove them one by one.

Eran
"Kevin Spencer" <ke***@takempis .com> wrote in message
news:O7******** ******@TK2MSFTN GP10.phx.gbl...
I can't imagine what sort of CSS you would use on a div which encompasses
everything in the page. You might as well apply a class to the <body> of the page if that's what you're after. I can certainly agree with and appreciate the use of divs in the page with classes on each one so that you can use CSS to position them and work with their styles, but the whole page? And if you use divs (or ASP.Net Panels) for your content, you dont' need to do anything outside of the WebForm, as that should encompass the entire contents of the viewable page.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:2D******** *************** ***********@mic rosoft.com...

I am absolutely not looking to touch the page template at all. I am using
program code only to build a page. I don't want to put any HTML in the page template at all because I have custom classes that make modifications to
many pages at runtime, and I don't want to hand-edit 223 pages with <div>
tags as I go, either. :)

I know that I want to place a the <div> inside the <body>, but then I want
to put everything else inside that <div>. That will let me use CSS to
define how the page flows overall, letting me handle silly user window
maximizes and etc.

The following almost works:

I make my <div> (it's an HtmlGenericCont rol) called myDiv.
Then I do a Controls.AddAt( pageBody.Contro ls.Count,myDiv) .
Then I do a myDiv.Controls. Add(myForm).
Then I do a pageBody.Contro ls.Remove(myFor m).

For some reason my form controls are now displaying outside of the <div>

style area I defined, but that might be a (mis)function of my CSS code.
Hmmm...




I'm not following you. If you want a div tag in your Page, just put one
there in the Page Template (.sapx). You can put any HTML you want into

the Page Template. And, according to the rules of HTML, and tag or element

that
is between the <div> and </div> tags will be inside the div, including

form
and all other Controls that render HTML objects in the page.

Offhand, it sounds like you're trying to do something oddly here. What is the requirement that this div is supposed to fulfill?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:6D******** *************** ***********@mic rosoft.com...
I would like to wrap all of the HTML inside of my <body> tag inside a

<div> with in my code-behind. I do not want to touch the .aspx page
template at all. I know how to make the body tag runat=server and give it an id so I can find it from the code-behind, but after that I want to add the <div>. One problem I see is that I just add the <div> to the <body>, all of the other controls (including the aspx <form>) will not be inside

it.> What can I do?
> Thanks.


Nov 18 '05 #7

You are right. When I said "everything " I should have written "everything .NET". There will be other contributing pieces of code that need to get placed in the body, and I don't want them to act the same as all my .NET stuff. For example, I am working on a menu system with its own <form> stuff and I don't want that CSS to get mangled by my "main" CSS.

Thanks to Kevin and Eran and Steven Cheng
I can't imagine what sort of CSS you would use on a div which
encompasses everything in the page.

Nov 18 '05 #8
You know, it sounds almost as if you'd be better off discarding the ASP.Net
Page class altogether and wiritng your own custom HttpHandler. Could be a
lot of work, though.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"localhost" <pr*******@coho rt.ces> wrote in message
news:18******** *************** ***********@mic rosoft.com...

You are right. When I said "everything " I should have written "everything ..NET". There will be other contributing pieces of code that need to get
placed in the body, and I don't want them to act the same as all my .NET
stuff. For example, I am working on a menu system with its own <form> stuff
and I don't want that CSS to get mangled by my "main" CSS.
Thanks to Kevin and Eran and Steven Cheng.

I can't imagine what sort of CSS you would use on a div which
encompasses everything in the page.

Nov 18 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6517
by: Jens Kristensen | last post by:
I have a problem displaying a divbox containing a html-textarea - everything works fine with "normal" characters. However, when the textarea contains special chars like <P> or ' , the box fails to show: function show(divbox) { divbox.style.display=''; } <div id="divbox" style="display:none" >
2
7574
by: listaction | last post by:
Hi Folks, can you help me by explaining how the code below can be translated using <div> and achieve the same effect? Thanks, LA <html> <body> <table bgcolor="#000000" width="100%" cellspacing="1">
5
2225
by: Mark Preston | last post by:
Admission first - I don't actually have a problem here but have noticed that a lot of people have been asking similar questions and getting very varied answers. What I've done is to sort of "compile the questions" into a theoretical problem to see what people think should be done to solve it. Maybe it will be a worthwhile discussion, but more importantly maybe it will find out the very best way to sort this kind of problem out so that...
9
3145
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
5
6970
by: Vear | last post by:
Hi, I have several <Div>'s that I have assigned an ID for. When the page loads It set the Absolute Position through a Style sheet. Can I then reference the <Div> through VB to move it to another Absolute. if so can you show me the VB syntax. Thanks
5
1791
by: Stan R. | last post by:
Greetings. I have a couple of questions concerning CSS layouts, as apposed to the old <tablemethod for creating layouts . Even after spending the last few days searching all over Google Groups, I haven't not been able to find a solution to my collective dilemma, and I hope some of you fine folks here in these neck of the UseNet woods might be able to share some wisdom with a fellow coder. My questions are in regard to what are the proper...
5
13525
by: Agix | last post by:
Hi there, Please check out : http://clarifysolutions.co.uk/certenroll/ The source is included below. This page is a test, so I can play about with paddings, margins and layouts using divs as semantically meaningless containers for bunch's of other elements - like everyone keeps telling me to make my code standards compliant. This request is not because I want a fix, but because I want to
6
5651
by: plumba | last post by:
Hi I have a check box which when ticked displays the sumit buttons of a form and gives the checkbox field a value of "agree". I would like to set the check box to hide the section of the form if the check is removed. I have included a small sample code from my form: <html> <script> function toggle_display() { var form = document.getElementById('hidesubmit');
1
1694
by: milas57 | last post by:
hello everyone i have a homepage which introduce the company website as shown below im having trouble to find some javascript code when i click on the header link like servives the body content changes dynamically. thank you ------------------------------------------------------------------- index.php <div id="header"> <a href="#" class="abt1">Services</a> <a href="#" class="abt1">Catalog</a> <a href="#" class="abt1">Partners</a> <a...
8
10047
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF editor. A fellow member of the PCG has helped me by creating a bit of Javascript to emulate the scrolling and using Google I've now gotten it into a state where it almost passes the W3C Markup Validation Service. However, the one error, Error Line 166,...
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.