Click here to Skip to main content
6,631,404 members and growing! (16,854 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Beginner License: The Code Project Open License (CPOL)

ASP.NET Controls - The Bridge between Client and Server-Side

By Nuno M. F. Gomes

A simple article about how client side data and events are made available on server-side.
Javascript, C# 2.0, Windows, .NET 2.0, ASP.NET, WebForms, VS2005, Architect, Dev
Posted:7 Feb 2007
Views:13,730
Bookmarked:12 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 4.01 Rating: 3.72 out of 5
3 votes, 25.0%
1

2
1 vote, 8.3%
3
1 vote, 8.3%
4
7 votes, 58.3%
5

Introduction

In my previous article I talked about attributes 'name' and 'id' length and why their size can easily grow.
In this article I will focus my attention answering "Why they are rendered and what are their roles in ASP.NET?".

Background

In concerning about attribute 'id' is role ends on client-side, i.e., this attribute it's only used by browsers engines and by programmers to, easily, find an html element in page. This very useful attribute is not required, and thus, is only rendered when programmers explicitly set ASP.NET Controls ID property value.

If you heavily use client-side scripting then you, certainly, thought why this attribute isn't always rendered. Well, try thinking on the opposite scenario, where all html elements have its own id attribute rendered, even elements that usually are not changed by script (like labels) and all the other that in your case are not needed. This last scenario seems to me a waste of resources, valuable resources like network bandwidth.

The role of attribute 'name' is far most complex. In fact, most of richness of ASP.NET user experience is built on top of its uniqueness.
Unlike 'id' the 'name' attribute is almost always rendered, and even when is not render directly to element attributes he could still be in use on script statements (usually the famous __doPostBack).
The 'name' attribute has two tasks to accomplish:

  1. The first come from the old ASP times and is the fact that 'name' value is used as key in the post values server-side collection (HttpContext.Current.Request.Form)
  2. The second, a new responsibility added by ASP.NET, is to delegate on 'name' value the responsibility of identifying uniquely the element source of current post back.

This last responsibility adds a new constrain to 'name' attribute value: it must be unique but it also must be something that maps directly to a single Server-Side Control, the same that previously render the 'name' attribute value.

To achieve this task, every ASP.NET Control has a UniqueID property that is built based on the control hierarchy. In order to ensure that a control always has the same UniqueID its assumed that his parent hierarchy is always built the same way, even dynamic controls should always be added at the same point of the Page Life Cycle.

Conclusion

As exposed in my previous article, sometimes 'name' and 'id' attributes grow more than we expect and we need to think about reducing their size. Any attempted should always preserve the second responsibility of 'name'. If that is not achieved then you will loose one major ASP.NET benefit:

the bridge between client and server-side that allows the raise of server-side control events like OnClick and OnChange (OnTextChange, OnSelectIndexChange, etc.).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Nuno M. F. Gomes


Member
Nuno Gomes currently works as a Senior Developer for one of the major portuguese banks.

Gomes graduated from Instituto Superior Tecnico with a Electronics and Computers degree in 1999.

His daily work main focus is, since 2003, on ASP.NET. A true .NET developer with great passion for the simple solution.
Occupation: Software Developer (Senior)
Location: Portugal Portugal

Other popular ASP.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
JokeRE: PinmemberJF_ROCHA1:37 8 Feb '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 7 Feb 2007
Editor:
Copyright 2007 by Nuno M. F. Gomes
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project