Data Mining

Download Free Data Mining Source Code In C/C++, C#, Visual Basic, Visual Basic.NET, Java,
and other programming languages
Welcome to Data Mining Sign in | Join | Help
in Search

Data Mining Source Code Newsletter

Business Analyst Training
Live, Online, Video Courses
Instructor-Led + Hands-On
BusinessAnalystBootCamp.Com

SQL + Database Training
Live, Online, Video Classes
Instructor-Led + Hands-On
SQLBootCamp.Com

Software Developer Training
Live, Online, Video Courses
Instructor-Led + Hands-On
SoftwareDevelperBootCamp.Com

IT CAREER COACH
Hands-On Experience Coaching
IT Skills Training
IT-Career-Coach.NET

IT Professional Newsletter
"Free" IT Career Success Tips
How To Accelerate Your Career
IT Career Newsletter

Ask IT Career Questions
"ASK" A Burning IT Career
Question Or Get Answers
Ask A Burning IT Question Now!

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed

Advanced Personalization Services in ASP.NET 2.0 Part3

Last post 02-19-2005, 4:50 by khaledhussein. 0 replies.
Sort Posts: Previous Next
  •  02-19-2005, 4:50 4137

    Advanced Personalization Services in ASP.NET 2.0 Part3

    Advanced Personalization Services in ASP.NET 2.0 Part3

     

    Khaled Hussein.

    E-Business Solution Developer

     

    February 2005

     

    Applies to:

    Microsoft ASP.NET 2.0

    Microsoft Access 2003

    Microsoft Visual Studio 2005 Beta 1 Codename "Whidbey"

     

    Summery: learn how to implement the third aspect of personalization features in your web applications using new ASP.NET 2.0 web parts.

     

    Introduction

    If you read part 1, and part 2 in the advanced personalization series, you would have figured out that till this moment, we were able to recognize the user and handle programmatically with our engines how to deal with their profiles and manage their personal information using the new technologies and server controls.

     

    Some people say well, I thought personalization is just customizing the way the page looks. Well these people are absolutely correct but this step wasn't an easy step to go. We had first to enable the user to sign up and identify him self to the web application or our system in order to enable the system to interact with the person. After interacting with the person and enabling the system to store statistics and information about that user, we can now give him the ability to change the layout, colors, or appearance of the web site.

     

    Web parts are simply one of the new tools that are offered by ASP.NET 2.0 and that we are going to use in order to provide flexibility to users to change the way the web site looks like, or to even choose their preferred contents and hide the other non interesting contents to them.

     

    Web parts are a set of server control that allows developers to quickly develop modularized Web pages that users can reorganize at run time.

     

    Web Parts Architecture

     

    You can think of web parts as page blocks. Each one of these blocks can be added or removed dynamically or at run time by the visitor to your web site and the interesting part is that without writing much code to do this (almost non). All the code to needed to hide or remove or to do any other functionality in web parts is handled automatically through the web parts manager.

     

    So we can think of web parts as three components:

     

    ·          Web part manager.

    ·          Web part zone.

    ·          Web part.

     

    All these three components can be found in the following namespace System.Web.UI.WebControls.

    These three controls combine together to create Web pages that are visually and functionally similar to complex desktop applications.

     

    Web part manager configures and manages the state of all the web parts found in the page.

    Web part zone provides the infrastructure for web parts and is used to define the screen region to contain the web parts.

    Web part is the base class outlining configuration properties that allow sub classes to be members of Web Part Zones. Generally, one or more controls will be encapsulated in a subclass of WebPart, or a GenericWebPart will be wrapped around a single user control.

    WebPart Code

    Building web parts

     

    Actually there are three ways we can use to build the web parts.

     

    First we can go for the easiest way which is just drag and drop any user control into the WebPartZone control in your page. GenericWebPart wrapper will be automatically created and encapsulate this added user control.

     

    Second we can create a control that inherits from WebPart class. This is a little more difficult way to build web parts but it gives more flexibility and more customizable controls as web parts. This approach can be used if we want to modify the behavior of the web part or we want to use the features and properties implemented in the web parts.  The most important method that you have to implement when you extend the WebPart class is RenderContents() which actually renders the control on the page.

     

    Third we create a new class that implements the IWebPart and IWebActionable interfaces. As it implies that the IWebPart defines several methods that is related to how a WebPart works, while IWebActionable defines several methods that are related to how a web part handles verbs and actions a user makes.

     

    A Simple Web Part

     

    The easiest way to build a page that contains web parts is to drag a WebPartZone and drag and drop any other server control into this WebPartZone. As everything else this method has advantages and disadvantages.

     

    Advantages include that this method is very effective in rapid web parts applications development. And it is very easy and productive method.

     

    Disadvantages include that it is automatically GenericWebPart is generated for every control found in the WebPartZone controls, and this will have a performance issue as there will be more than one GenericWebPart. Secondly that the advanced features and functionalities found in web parts aren't provided or available in GenericWebPart.

     

    The approach to use this method is to make a custom user control and include in it all the other controls that we want to use, and then add this custom user control to a WebPartZone so that there will be only one GenericWebPart generated at runtime which will definitely has a better performance to your web application.

     

     

    A Derived Web Part

     

    As you now know that the GenericWebPart object doesn’t include all the complex functionalities of WebPart object thus the second method is creating a new class that is derived from WebPart class to expose all of the functionalities included in WebPart.


    WebPart Manager

    In the above code we created a CustomWebPart class that inherits from WebPart and as you can see we are overriding the method called RenderContents() so that we can render or write the output of the control to the page as we want.

     

    Of course this code is just used for simplicity but we can include any business logic in there and then we choose the way that we want to render the output so that it is a meaningful web part.

     

    Implementing Interfaces

     

    The third method or way of implementing a web part is to implement IWebPart and IWebActionable interfaces. But you should only go to this method if you need to have FULL control over all the aspects provided in the web parts framework. In most cases you will need just to inherit from WebPart class and avoid overriding all of the web parts framework functionalities.

     

    Web Part Zone

     

    A web part zone is a container or a region of space that contains a collection of other web parts. It defines properties that control the look and feel of the components that are within its contained scope.

     

    A Web Part Zone must be configured with a unique id attribute, which is used by the Web Part manager control to identify a particular zone within the page. The title is displayed as a header for the Web Part Zone when editing page layout.

     

    Web part verbs

     

    Web part verbs are user friendly interfaces that are meant for some actions the user can do. We can think of these actions or verbs as the standard commands that we use in most of our windows applications.

     

    Web part zone defines the following standard verbs:

     

    Close: which enables the user to close the web part zone (or hide it).

    Minimize: which enables the user to minimize or hide the contents only leaving the title of the web part zone visible on the page.

    Restore: which enables the user to show the contents that were invisible on a minimized web part zone.

    Help: The developer can assign help notes that can be viewed by the user if he clicked on help.

     

    Web Part Manager

     

    Web part manager is the responsible control for keeping track of the state of all web parts in the page. And it must be added to the page before any web part zone to be able to track it.

     

    For each page that exposes the functionality of the web parts it must have one and only one web part manager and as we mentioned it must be put before any other web part zone.

     

    The Web Part manager control's DisplayMode property is of particular interest, because it defines the type of configuration options available to the end user. DisplayMode has several possible values.

     

    • Catalog—Displays a list Web Parts and allows parts to be rearranged. The WebPartManager's catalog zone becomes visible to the user. Web Parts can be selected, and then added, to one of the page's zones by using the add button. This is the only mode in which Web Parts can be added to the page.
    • Design—allows the user to rearrange Web Parts on the page.
    • Edit—allows a user to edit specific attributes of individual Web Parts.
    • Connect—Provides communication between two Web Parts
    • Browse (which is the default display mode)—Displays the page with user preferences applied.

     

    Conclusion

     

    With the new personalization features in ASP.NET 2.0, however, developers can not only create personalized applications faster, they can also build entirely new classes of applications. The user management system and login controls make recognizing a user even easier than before, and the profile features help store user data in a fast and efficient manner. The Web Parts framework, however, provides a revolutionary new design paradigm for Web sites.

Announcing The Data Mining Source Code Newsletter!

Subscribe By Email | Subscribe By RSS Feed