Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Dynamically Adding Wired Controls to Web Forms : Page 4

Dynamically creating Web controls and adding them to a Web Form can be a challenging process. A thorough understanding of how the ASP.NET engine instantiates controls as well as the event life cycle of Web Forms is crucial to success.


advertisement

Dynamic Control Creation Limits

You cannot dynamically create a control and wire an event into it in a cached event or in the PostBack event. Cached events and the PostBack event get processed after the OnLoad() function member and OnInit() function member have completed processing.
You should know about one important limitation in the sequence that ASP.NET uses to process events that directly impacts my technique for dynamically creating controls. You cannot dynamically create a control and wire an event into it in a cached event or in the PostBack event. ASP.NET processes cached events and the PostBack event after the OnLoad() function member and OnInit() function member have completed processing.

Many complex Web applications require forms to be created and rendered dynamically. The ability to dynamically add controls and content to forms has been an intrinsic feature of both classic ASP and ASP.NET. Microsoft ASP.NET vastly expands the process. Expertise in the dynamic creation process requires a thorough understanding of the ASP.NET page event life cycle.

Resources
You'll find additional resources on the Web by searching for the ASP.NET page event life cycle.

Here is an MSDN article that discusses the page event life cycle in detailhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcontrolexecutionlifecycle.asp.

The MSDN Web site lists an article that discusses how to dynamically create Web Form controls:http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317794. This is the C# version of the code. There is a link at the bottom of the article for the Visual Basic .NET version of the article.



Shannon Horn is the co-founder and chief software architect of WebGeniuses Corporation (http://www.webgeniuses.com). He is a Microsoft Certified Application Developer (MCAD), Microsoft Certified Solution Developer (MCSD), and a Microsoft Certified Trainer (MCT) who has been developing Microsoft Windows and Web-based solutions as well as training for over 12 years. He has been a featured speaker at many industry events including Microsoft DevDays and asp.netPRO's ASP.NET and Web Services Solutions conference. He is a published author on subjects such as XML, migrating from Visual Basic 6 to VB .NET, Jscript .NET, Visual C# .NET, and ASP.NET.

Shannon speaks and trains for companies such as AppDev (http://www.appdev.com) and LearnIt (http://www.learnit.com) and has been a featured speaker on training videos with LearnKey. He has also worked with large corporate clients including Universal Studios, MGM Studios, Monster.com/FlipDog.com, Intel, Polygram Pictures, Prudential, Micro Accounting Systems, Sky Harbor International Airport, and Southern Automated Systems on projects using Microsoft technologies such as Visual FoxPro, Visual Studio .NET, C#, ADO.NET, and ASP.NET. Shannon lives in Glendale, AZ, and is married with two daughters and a son. shannon_horn@webgeniuses.com.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date