Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2008, 03:16 PM
Authorized User
 
Join Date: Apr 2008
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 Small Question

Just a small question from chapter 9. How come you don't have to surround the textboxes and submit button with a form tag? Normally wouldnt you set it up to wrap a <form tag around it with action attribute?

I'm a bit confused how this works?

 
Old April 28th, 2008, 03:24 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

All ASP.NET pages include a single form control that surrounds everything else inside of the <body>. This is created for you when you create a new web form. The validation demo page will have this form control.

When you create a master page, typically it will contain the main form control. The content placeholder will be inside of that form control such that any content page is implicitly a child of that form control.

-Peter
peterlanoie.blog
 
Old April 28th, 2008, 03:39 PM
Authorized User
 
Join Date: Apr 2008
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is it good practice to re-name that form wrapper?

 
Old April 28th, 2008, 03:53 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I would hesitate to make the claim that it is either good or bad practice.

You can change the ID of the form, it won't make much of a difference. You may also notice that the ASP.NET runtime will rename it anyway. There isn't much point in giving it a name for that reason.

If you are trying to write client side code that expects the form to be a particular name you may run into problems. It's typically better to provide the full client name of the element you want to manipulate and use that instead of going thru the form via the DOM hierarchy.

-Peter
peterlanoie.blog
 
Old April 28th, 2008, 08:17 PM
Authorized User
 
Join Date: Apr 2008
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do have to have that form surrounding the whole page?

As well with the controls, I'm a code neat freak. With these controls, the HTML output is horrendous. You can use controls and normal coding combined correct?

I also like seeing the way things work behind the scenes. Is there anywhere I can find out the underlying code for the controls?

 
Old April 28th, 2008, 08:32 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

As Peter pointed out to me on a recent project, not ALL ASP.NET controls require that they appear inside of the form control, however, most of them do.

I am not sure what you mean by "normal" coding?

Also if by viewing the underlying code you mean looking at what makes a Calendar control a Calendar control, for example, yes this is quite easy to do. I would suggest a program like Reflector: http://www.aisto.com/roeder/dotnet/

This app has a built in disassembler that will allow you to take a look at the code under the hood so to speak and also show you the Interfaces, members, properties, etc of a given assembly.

Here is what the DayRender event of the calendar control looks like:

protected virtual void OnDayRender(TableCell cell, CalendarDay day)
{
    DayRenderEventHandler handler = (DayRenderEventHandler) base.Events[EventDayRender];
    if (handler != null)
    {
        int days = day.Date.Subtract(baseDate).Days;
        string selectUrl = null;
        if (this.Page != null)
        {
            string argument = days.ToString(CultureInfo.InvariantCulture);
            selectUrl = this.Page.ClientScript.GetPostBackClientHyperlink( this, argument, true);
        }
        handler(this, new DayRenderEventArgs(cell, day, selectUrl));
    }
}

Most of the controls you will want to look at are contained in the System.Web assembly underneath the System.Web.UI.WebControls namespace.

hth.

-Doug




================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old April 28th, 2008, 08:55 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

aspcoder-

Unfortunately, once you get into the realm of ASP.NET you loose a certain amount of control over the emitted HTML. Like yourself, I was once obsessed over the cleanliness of my emitted HTML when I worked in ASP and had good control over it. But since moving into .NET I've found that while the code isn't perfectly formatted, it is structured well and pretty good structurally. The trade-off of less explicit control is well worth the advantages provided by ASP.NET. There are ways to hijack the rendering process and you could write your own rendering engine, but is it really worth it? Probably not.

As they add controls that give us more control over the emitted HTML (such as the ListView control in 3.5) it becomes easier to strongly dictate the HTML you want to use in complex controls that support data binding.

You can use "normal coding" if by that you mean literal HTML. There's nothing to stop you from writing out your own literal HTML tags. In the end everything between a > and < of a server control (i.e. runat="server") will exist as an instance of a LiteralControl class in the page's control hierarchy. ASP.NET will just treat it as a long string of plain text that gets emitted to the output stream as-is. Of course, you need to provide well formatted HTML if you don't want the page to break in the browser, and you won't be able to put a <form> tag in it without breaking the webform/postback behavior model. Aside from that, your free to do just about anything.

Quote:
quote:Do have to have that form surrounding the whole page?
This is typically how it's done because all controls on the page are part of the web form. Granted the end result of the controls (i.e. the emitted HTML) may not result in form input elements, but ultimately it doesn't really matter where the form starts and ends. It's going to be on the page regardless. It's an integral part of how ASP.NET works.

-Peter
peterlanoie.blog
 
Old April 28th, 2008, 09:31 PM
Authorized User
 
Join Date: Apr 2008
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Like from a creation point of view, in Visual Studio, everything is clean cut, and read-able. Code is separated from markup. But I guess the whole thing is, if it works, your end user's don't know the difference. I was looking at it from a corporate perspective. If someone else is reading my code I want them to be able to change it easily and I guess that is what I was getting at before. My clean HTML and CSS formatting days are gone it seems ! :)

This is something I'm going to need to get used to. I was getting a little frustrated because I like to know what code does, and when I drag a control onto a page I didn't know the 'inner workings' of that particular control.




 
Old April 29th, 2008, 12:23 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by aspcoder
 Like from a creation point of view, in Visual Studio, everything is clean cut, and read-able. Code is separated from markup. But I guess the whole thing is, if it works, your end user's don't know the difference. I was looking at it from a corporate perspective. If someone else is reading my code I want them to be able to change it easily and I guess that is what I was getting at before. My clean HTML and CSS formatting days are gone it seems ! :)

I wouldn't say that at all. You can certainly still have clearly separated and clean HTML and CSS in your page markup, no less than before. The only real difference is that instead of writing literal HTML you are using server controls that generate their own HTML. If you use the controls' styling properties, they'll generate some messier output with inline styles, but you don't have to. You can assign css class(es) to them and still use standard CSS, in fact it's advisable to do so. And certainly there is a clear distinction between the markup of the page and the page's server side functionality with the code behind files.

Quote:
quote:Originally posted by aspcoder
 This is something I'm going to need to get used to. I was getting a little frustrated because I like to know what code does, and when I drag a control onto a page I didn't know the 'inner workings' of that particular control.

That's the trade-off with any framework. Unless you build it all from scratch yourself, there will always be a certain amount of "black-box" factor with it. However, the more you use the controls the more you'll understand how they behave. You may not see the raw innards of them but you'll recognize the patterns.

When in doubt, ask here, there are plenty of folks who've been doing this for long enough to know the nuances of the controls and of ASP.NET in general.

-Peter
peterlanoie.blog
 
Old April 29th, 2008, 12:56 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Once you get the hang of ASP.NET, you may want to take a look into ASP.NET MVC. It's quite different from the current Web Forms technology, but it gives you back full control over the HTML.

To get started, check out this blog post:
http://weblogs.asp.net/scottgu/archi...framework.aspx

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on Chapter 5 arholly BOOK: Expert Access 2007 Programming ISBN 978-0-470-17402-9 1 September 2nd, 2008 04:07 PM
Chapter 4 question davidle1234 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 January 18th, 2007 12:18 AM
Chapter 5: DataLayers Question pointblank BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 23rd, 2006 09:39 AM
Small rookie question maximus101 VB Databases Basics 1 February 23rd, 2006 11:51 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.