Blog Home  Home Feed your aggregator (RSS 2.0)  
What did you learn today? - 70-551 - Section II Part VII - Web User Controls
Phil Denoncourt's Technology Rants
 
 Monday, February 27, 2006

UPGRADE: MCAD Skills to MCPD Web Developer by Using the Microsoft .NET Framework

Create a composite Web application control.

  • Create a user control.
  • Convert a Web Forms page to a user control.
  • Include a user control in a Web Forms page.
  • Manipulate user control properties.
  • Handle user control events within the user control code-declaration block or code-behind file.
  • Create instances of user controls programmatically.
  • Develop user controls in a code-behind file.
  • Create a templated user control.

Add New Item->Web User Control.

There is an article on MSDN on how to convert a page to a user control.  It's a little easier than in 1.1 if you are using single-file pages.  Rename to .ascx, change @Page to @Control. Remove HTML, Body and Form tags from the HTML Code.

There is also an article on MSDN on how to include user controls in a page.  Add a Register directive to the top of the page, specifying a prefix, tagname and a relative URL to the user control.  You can also now drag the user control from your project onto the page and it will wire it up.

You manipulate a user control as you would any other control, through a member variable of the page.

To handle a user control event within the user control code declaration block, you add it the event as an attribute to the tag.  Here is an example of a usercontrol that has an event named TextStringChanged.

<uc1:MyUserControl ID="MyUserControl1" runat="server" TextString="Phil was here" OnTextStringChanged="TextStringChanged"/>

To handle it in the code-behind file, you treat it like a event on any other type of control.  Add a event handler delegate to the event.

To programatically create a usercontrol, use the LoadControl method of the Page.  That returns a reference to a new instance of the user control.  Then you must add it to a controls collection in order for it to appear on a page.

Creating templated usercontrols sounds tricky, but it's not that bad.  Try the walkthough on MSDN .

Next up->Copy / Publish Web tool

Monday, February 27, 2006 7:33:43 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]   Certifications  | 
Comments are closed.
Copyright © 2008 Phil Denoncourt III. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: