• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

ASP.NET not wrapping Textbox in DIV

On this page http://msdn.microsoft.com/en-us/library/exc57y7e.aspx under 'ASP.NET Features for XHTML Conformance', it says

Because XHTML requires all elements to be enclosed in a container element, ASP.NET controls, such as input elements, are rendered in div elements. This includes the HTML markup rendered for controls, such as the TextBox, CheckBox, and RadioButton controls. It also includes hidden fields, such as the element that is used to store view-state data.

However, if you create a new web app and drop a textbox below the last div in designer source view then run the app, that textbox won't be surrounded in a div.  It will sit above the closing form tag.  Is MSDN doc incorrect?
0
brettr
Asked:
brettr
  • 4
  • 4
1 Solution
 
hehdaddyCommented:
I am not sure if MSDN is correct or not, but if you are using a page with a DOCTYPE of XHTML... then your page just must be properly formed.

Controls must exist in a container. In this case, you have the form tags, body tags, etc. as your containers. The controls don't have to be in a div.
0
 
strickddCommented:
What the documentation is saying is that all tags need an opening and closing tag.

<a></a>
<asp:TextBox/>
<asp:TextBox></asp:TextBox>

Since you are dropping it outside the <form></form> tags, it is erroring because <asp:*/> controls are considered form controls.
0
 
brettrAuthor Commented:
@hehdaddy:

It says, "...are rendered in div elements."  Which looks like an absolute statement.  It starts off saying containers but then restricts down to only divs.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
hehdaddyCommented:
How the page is rendered depends on the DOCTYPE of the aspx page. What is your DOCTYPE?
0
 
brettrAuthor Commented:
Transitional 1.0 - asp.net default.
0
 
hehdaddyCommented:
Transitional doesn't require <div> containers. If you use a Strict DOCTYPE then it will.

Here is a great post on DOCTYPEs:

http://www.alistapart.com/articles/doctype/
0
 
brettrAuthor Commented:
I've tried it with Strict but still don't see input being wrapped in a DIV.  I've added the entry into the web.config as well.  Code and output are included below.  Notice the last textbox is output of any DIV.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DocType._Default" %>
 
<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:Panel ID="Panel1" runat="server">
        </asp:Panel>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    
    </form>
</body>
</html>
 
 
 
//web.config
<system.web>
    <xhtmlConformance
        mode="Strict" />
</system.web>
 
 
//runtime output
 
 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
 
</title></head>
<body>
    <form method="post" action="default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTEzMzM3ODM1MzdkZDEsMS2JCWq42C/8/F6g6j3D5Ywm" />
</div>
 
<div>
 
	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKq47KYDgLs0bLrBgKM54rGBgLs0fbZDBS6p3gS5TNZ7/fEl7IqlzON0NzX" />
</div>
    <div>
    
        <div id="Panel1">
	
        
</div>
        <input name="TextBox1" type="text" id="TextBox1" />
        <br />
        <br />
        <span id="Label1">Label</span>
        <br />
        <br />
        <input type="submit" name="Button1" value="Button" id="Button1" />
    </div>
    <input name="TextBox2" type="text" id="TextBox2" />
    
    </form>
</body>
</html>

Open in new window

0
 
hehdaddyCommented:
I have run my own tests. It appears that the Microsoft documentation is wrong. That is actually very common.
0
 
brettrAuthor Commented:
Thanks.  You are saying that input will not be wrapped in a DIV, as stated by MS?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now