Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2
This is the forum to discuss the Wrox book Professional ASP.NET 2.0 Server Control and Component Development by Dr. Shahram Khosravi; ISBN: 9780471793502
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 25th, 2007, 04: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
  #2 (permalink)  
Old July 25th, 2007, 04:26 PM
Imar's Avatar
Wrox Author
Points: 71,796, Level: 100
Points: 71,796, Level: 100 Points: 71,796, Level: 100 Points: 71,796, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,037
Thanks: 80
Thanked 1,580 Times in 1,557 Posts
Default

I guess you could, theoretically.

However, I am not so sure I like this model. While it works from a technical point if view, I think it can be hard to use at design time. You have partial tags in different files, making it hard for a developer to find out what goes where. In addition, tools support may be hard, resulting in many errors...

If your point is to illustrate the book is not technically correct: I completely agree. If your point is to partition logic across your application, you may be better off using Master Pages and user controls with self contained elements.....

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old July 25th, 2007, 04:46 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

Hi Imar,

Yes, I just wanted to point out technical inaccuracy and I completely agree that such style should be avoided in a real code. On the other hand, sometimes we HAVE TO push all the available ASP.NET arsenal to its limits so it is better to be aware of all the capabilities.

Best regards,
Alexei
  #4 (permalink)  
Old July 25th, 2007, 05:50 PM
Wrox Author
 
Join Date: Aug 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
The book is technically correct and accurate. User controls can be used for partitioning logic across your pages. For example, you can have a user control that contains the beginning tag of a <tr> element and another user control that contains the ending tag of the same </tr> element. However, such partitioning should not be applied to html, body, and form containing elements. In other words, user controls should not include html, body, and form elements because a user control as a reusable piece of code is merged into pages that normally contain the html, body, and form elements.

Cheers!
Shahram

-----------------------
Shahram Khosravi, Ph.D.
Author of Professional ASP.NET 2.0 Server Control and Component Development
  #5 (permalink)  
Old July 26th, 2007, 01:06 AM
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

Hi Shahram,

I can't agree with you. In my opinion, the text of the book states that one CAN'T USE html body and form tags in a user control.
Sorry if it is my English that is to blame but in your post above you use "shouldn't" but in the book the text is "can use except ..." which means "can't use" i.e. it apparently sounds like it is not technically possible. But it is not the case (see my example in the first post of the topic). I agree that for the most part it is not necessary but theoretically, for example, one can use footer user control which includes closing </body> or/and </html> tag, or user control which includes entire <form /> element.
And another difference between the text of the book and your post. In the book you use term "tag":
Quote:
quote:...can use any HTML tag except for html ...
but in the post you use "element" term:
Quote:
quote:...should not include html, body, and form elements
If you meant html body or form elements in the text of the book then there is another inaccuracy which is not acceptable in any professional book when these terms (tag and element) are used interchangeably.
But even in this case I can use ANY of the mentioned HTML elements (with their content) in a user control.

Of course it is not necessarily in ASP.NET 2.0 with its master pages mechanism, but it is still possible. As a part of my current project we have to use ASP.NET 1.1 and in the project custom templating xml-configured mechanism was designed where UserControls are used to create consistent layout. So upper-level user control contains html and body element, and lower-level user control contains form element (and user controls of lower levels) and there is nothing wrong with it.

And another final argument closely related to ASP.NET 2.0. Isn't MasterPage class derived from UserConrtol? Do you mean that I can't use html body or form element in a master page or in any nested master page?

So, once again, as far as parser can build parse tree from the markup the user control is valid.
Thus I can't agree that there is no technical inaccuracy in the mentioned paragraph.

Best regards,
Alexei
  #6 (permalink)  
Old July 26th, 2007, 05:18 AM
Wrox Author
 
Join Date: Aug 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
As the title of this book clearly states, this book teaches readers how to develop components. A component by definition must be reusable. The keywords here are components and reusability. You can't use containing elements such as html in a user control if you're designing the user control to be a reusable component where it is required to merge with different types of hosting pages without conflicts.

Sure if you don't want your user control to be a reusable component, you can include elements such as html.

Cheers!
Shahram

-----------------------
Shahram Khosravi, Ph.D.
Author of Professional ASP.NET 2.0 Server Control and Component Development
  #7 (permalink)  
Old July 26th, 2007, 05:34 AM
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

Hi,
My main idea that it IS technically possible to use user controls in such a way, so the paragraph IS NOT technically accurate.

My second point is that user control CAN BE A CONTAINER for other controls, so even in case this user control contains such elements as <html />, <body /> or <form /> it CAN BE REUSABLE with different content loaded dynamically. Have you noticed my earlier post were master pages were mentioned? It is the very same example. Also I mentioned a concept of using user controls to design consistent layout for ASP.NET 1.1 to emulate master pages.

Sorry, but for me it looks like your main point is just to prove there is no technical inaccuracy in the paragraph of the book, while apparently there is.
  #8 (permalink)  
Old July 26th, 2007, 05:44 AM
Imar's Avatar
Wrox Author
Points: 71,796, Level: 100
Points: 71,796, Level: 100 Points: 71,796, Level: 100 Points: 71,796, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,037
Thanks: 80
Thanked 1,580 Times in 1,557 Posts
Default

I think it's all a definition issue here. I think we all agree on the intentions and the best practices, but definitions make it hard to agree with each other....

I have to go with Alexei in that *can't* means that it won't work. When things can't, they will crash, you get compile errors or will otherwise blow up.

*Shouldn't* on the other hand will work, but is not recommended and will get you into trouble somehow, somewhere, later down the road.

So, I think one should say "you shouldn't use the <html> tags in a user control" instead of "you can't use the <html> tags in a user control" if your aim is to create reusable components.

Cheers,

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old July 26th, 2007, 06:02 AM
Wrox Author
 
Join Date: Aug 2006
Location: , , .
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I don't agree with you, Imar and Alexei. Obviously, we have our disagreements on this issue and that is fine. Let just agree to disagree.

Cheers!
Shahram

-----------------------
Shahram Khosravi, Ph.D.
Author of Professional ASP.NET 2.0 Server Control and Component Development
  #10 (permalink)  
Old July 26th, 2007, 06:28 AM
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

Thanks for the discussion.

Alexei

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8: User Controls - Shows all banners VeganMan BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 April 9th, 2008 04:45 PM
User Controls Lofa ASP.NET 1.0 and 1.1 Basics 2 February 13th, 2006 01:04 PM
User Controls Duncan Pro VB.NET 2002/2003 2 December 1st, 2003 05:41 AM
User Controls Duncan Pro VB.NET 2002/2003 1 October 27th, 2003 12:51 PM
User Controls raZZa VS.NET 2002/2003 3 July 30th, 2003 08:36 AM



All times are GMT -4. The time now is 05:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.