Presentation is loading. Please wait.

Presentation is loading. Please wait.

Web User Controls This presentation will cover the basics of defining, creating and using a web user control. Presented to Twin Cities.NET user group By.

Similar presentations


Presentation on theme: "Web User Controls This presentation will cover the basics of defining, creating and using a web user control. Presented to Twin Cities.NET user group By."— Presentation transcript:

1 Web User Controls This presentation will cover the basics of defining, creating and using a web user control. Presented to Twin Cities.NET user group By Joseph White Chief Architect, Eden Systems International http://www.EdenSI.com August 5 th, 2004

2 About Your Speaker Name: Joseph White - JoeCasa1@Yahoo.com Occupations: – Chief Software Architect for Eden Systems International –.NET mentor and architect (part time contracting available through ILM, your.NET solution provider) –Self Proclaimed “Lazy Programmer” Experience: –Working with.NET for over 3 years, developing software solutions, teaching and mentoring for over a decade.

3 Web User Controls First, Let’s resolve the name ambiguity –User Controls Could be confused with windows forms controls. –Server Controls Not ambiguous if you know what you are talking about. –Custom Controls Just as confusing as user controls. –Web Controls Used interchangeably to reference either web user controls or server controls.

4 Web User Controls What they are: –Similar in functionality to ASP include files but much better. –Encapsulate HTML and code into smaller functional units. –Built similar to web forms but hosted on a page as an object. –Reusable within the web project that hosts them.

5 Web User Controls What they are NOT –They ain’t server controls. –Easily distributed or shared across multiple web projects. –Something you would want to package and sell to the public.

6 Web User Controls Why not just use an old fashion include? –Include files are not encapsulated objects. Potential variable name conflict with host web page or other instances of the “included” code. Can not be programmatically manipulated by host page. Web user controls contain properties and raise events which provides fluid interaction between the control and the hosting page. Why not create a server control? –Too much work.

7 Web User Controls Let’s take a peek at what they look like in Visual Studio

8 Two part entry into the aspx page. Part 1: The declaration. TagPrefix: This is like a namespace in case you want to include other controls with the same name. Usually defaults to uc1. TagName: Again its only significance is to help uniquely identify the control on the page. Usually defaults to the name of the class. Src: Let’s the page know where it can find the ascx file that goes with the control. Web User Controls

9 Part 2: The actual control tag. TagName TagPrefix Unique instance identifier Required if manipulating on Server

10 Let’s Make a Simple Control

11 Web User Controls Things to Note: The control does not declare itself in the code behind. –Use Page.FindControl. –Manually type in the declaration. The properties do not show up in the property sheet. The design view can be drastically different from the runtime view. –In fact, when placed in a repeater control, they become invisible in the designer. A web user control can host another web user control.

12 ASP.NET Validation Controls Special kind of server controls used for validating input values entered in other server controls. A variety of validation controls allow us to require input, check for formats, compare with other fields, and perform custom operations.

13 Web User Controls Using Validators in a web user control Encapsulate Complex Validation Logic Validators in the user control will work with the validation summary control on the page. Because the web user control is web project specific it is easy to give validators a consistent look throughout the application.

14 Web User Controls Complex regular expression: (0?[1-9]|1[0-2])/([0-2]?[0-9]|3[0-1])/((1|2)\d{3}|\d{2}) ([0- 1][0-9]|[2][0-3])[0-5][0-9] Evaluates mm/dd/yy or mm/dd/yyyy with the leading 0 on the month or day being optional. Then it ends with HHMM where leading zero is not optional.

15 http://www.ilmservice.com Validation Controls Demo

16 Web User Controls Working with style sheets. Style Sheet Advantage: –Since the controls are site specific you don’t have to worry about all sorts of properties to handle styles. Style Sheet Disadvantage: –Since the style sheet is declared at the page level, your control (ascx file) may not look quite right in the VS designer.

17 Web User Controls Working with client side script Best Practice for large script blocks is to use an include file. Since a control may be included more than once on a page, It is important to make sure the script functions are only included once. –Use Page.RegisterClientScriptBlock and Page.IsClientScriptBlockRegistered

18 Web User Controls Conclusions Pros: Easy to create: –Same programming model as ASP.NET Page Code Behind Page Load event Post Back events Encapsulate complex expressions, functions and html code. OO approach avoids the pitfalls of copy and paste or old fashion includes.

19 Web User Controls Conclusions Cons: Doesn’t play well with the VS designer. –Renders as a gray box in design view. –Exposed properties not available in property sheet. –Does not declare itself in the code behind. Difficult to share across multiple web projects. Can’t package and sell as a stand alone DLL.

20 Web User Controls Thank you for your attention.


Download ppt "Web User Controls This presentation will cover the basics of defining, creating and using a web user control. Presented to Twin Cities.NET user group By."

Similar presentations


Ads by Google