View Single Post
  #1 (permalink)  
Old July 25th, 2007, 03:15 PM
AGS AGS is offline
Wrox Technical Editor
Points: 267, Level: 5
Points: 267, Level: 5 Points: 267, Level: 5 Points: 267, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2005
Location: Russia
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default User controls' content: Chapter 2 User Controls

Hi,
Chapter 2 (Page 32) contains following paragraph (emphasis is mine):
Quote:
quote:3. Add HTML markup text and ASP.NET server controls to the text file. You can use any HTML
tag except for html, body, and form. This is because user controls cannot be used alone and
must be used as part of a hosting Web page.
This is the third difference between a user control
and a Web page. Because a Web page stands on its own, end users can directly access it. The
same doesn’t hold true for user controls.
Maybe I am wrong but I can't see any restriction that doesn't allow me to use ANY of the elements mentioned above in a user control.
For example I could partition my page like following

Default.aspx
Code:
<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc" TagName="Header" Src="Header.ascx" %>
<%@ Register TagPrefix="uc" TagName="Form" Src="Form.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<uc:Header runat="server" />
<uc:Form runat="server" />
Header.ascx
Code:
<%@ Control Language="C#" ClassName="Header" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Some title</title>
</head>
<body>
Form.ascx
Code:
<%@ Control Language="C#" ClassName="Form" %>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
    </div>
    </form>
</body>
</html>
As long as don't partition any single server control between different user controls and parser can build parse tree, there is nothing wrong with any permutations of HTML tags that will be parsed and added to control's hierarchy as LiteralControls.

Best regards,
Alexei

__________________
Alexey Gorkov