?
Solved

ASP.NET not wrapping Textbox in DIV

Posted on 2009-04-30
9
Medium Priority
?
456 Views
Last Modified: 2013-11-26
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
Comment
Question by:brettr
  • 4
  • 4
9 Comments
 
LVL 6

Expert Comment

by:hehdaddy
ID: 24272125
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
 
LVL 28

Expert Comment

by:strickdd
ID: 24273034
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
 

Author Comment

by:brettr
ID: 24273262
@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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:hehdaddy
ID: 24275017
How the page is rendered depends on the DOCTYPE of the aspx page. What is your DOCTYPE?
0
 

Author Comment

by:brettr
ID: 24275029
Transitional 1.0 - asp.net default.
0
 
LVL 6

Expert Comment

by:hehdaddy
ID: 24275448
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
 

Author Comment

by:brettr
ID: 24279004
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
 
LVL 6

Accepted Solution

by:
hehdaddy earned 2000 total points
ID: 24283194
I have run my own tests. It appears that the Microsoft documentation is wrong. That is actually very common.
0
 

Author Comment

by:brettr
ID: 24291907
Thanks.  You are saying that input will not be wrapped in a DIV, as stated by MS?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question