Malaika Consultants LLC

Step 6: Handling Menus Effectively in ASP.NET

by Jane Thomson 23. August 2011 18:05

After learning few user controls and ASP.NET Master Pages, let us look at how menu handling can be done with ASP.NET. It is really difficult to maintain the website menu of a large website and it also takes more time. A menu is generally stores inside a file in ASP.NET to make its handling easier. The file where the menu is stores is known as web.sitemap file and it is kept under the root directory on the website.

Apart from the menu, ASP.NET also contains three different navigation controls as well.

1.    Sitemap Path

2.    Tree Views

3.    Dynamic Menus

Sitemap is actually an XML file and it can be created like a regular xml file with few special tags. Let us first look at few rules to create the web.sitemap file.

1.    The sitemap file has to have <sitemap> tag that surrounds the file content.

2.    The tag <sitemap> can have only one child node that is <siteMapNode> which actually is for home page.

3.    However, <siteMapNode> can have more than one child nodes which represents web pages of the website.

4.    Each of the <siteMapNode> has at least two basic attributes of page URL and page Title.

5.    A valid web.sitemap file cannot contain a duplicate URL and URL attribute can be left empty as well.

It is important to note again that a sitemap file must be placed under the root folder and the URL attributes must be assigned with the relative path of root folder.

Here is an example of a sitemap file.

<?xml version="1.0" encoding="ISO-8859-1" ?>
<siteMap>
  <siteMapNode title="Home" url="/aspnet/providern_home.aspx">
    <siteMapNode title="Article Writing" url="/aspnet/ providern_article_writing.aspx">
      <siteMapNode title="SEO" url="/aspnet/providern_SEO.aspx"/>
      <siteMapNode title="Link Building" url="/aspnet/providern_link_building.aspx"/>
    </siteMapNode>
  </siteMapNode>
</sitemap>

It is also possible to use more than one sitemap files in order to portray the navigation structure of the website. For an example, a sitemap file in a root folder can be linked to a child sitemap file by referencing child sitemap file in siteMapNode element of the file.

 

Tags:

Step 5: ASP.NET View-State

by Jane Thomson 1. May 2011 23:31

After learning a web form and few of the ASP.NET controls, let us look at one of the prime feature of ASP.Net known as View-State. If you have been as ASP developer, you must know that once you submit the form, all the values from the form are cleared. Now, suppose the server comes up with error! Haah, that’s really a bad situation for user and has to refill all the information on the form, and that’s something you want to avoid as a developer.

ASP.NET View-State feature provides exactly the same. As a user if you find that the value you submitted still remains there even if the server gives an error and you press back button, think blindly that the web page is developed with ASP.NET View-State feature.

Basically, ASP.NET View-State is a method used by the ASP.NET pages to persevere the changes of state of a web form across the postbacks. Actual thing is that the ASP.NET maintains the view-state of your form. View-State defines the value of the web page at the time of submission to server. The current status of the web form is maintained with a hidden element places on each of the page with a form control.

It’s a default setting of ASP.NET to maintain the View-State of ASP.NET. In case, if you do not want to maintain a View-State of a web form, you shall include directive, <%@ Page EnableViewState="false" %> on top of the web form. Or else you can also add the element EnableViewState = “false” to any of the controls on the page.

A developer shall use ASP.NET View-State if he/she wants to achieve one of the below features in web page:

·         Save the form values between postbacks even without saving it in a user profile.

·         Save page control property values defined by a developer.

·         If a developer wants to store the view-state information in any data storage.


For Step 6 please click here.

 


Tags:

Step 4: ASP.NET Master Pages

by Jane Thomson 1. May 2011 23:27

ASP.Net Master Pages are one of the recent features added in ASP.Net. This feature allows a user to apply same kind of page layout to all the pages of the web application or a website. A web page which uses the master page is also known as the content page. Previously, there was consistent issue faced by users regarding not to have a feature that allow users to give a consistent look across multiple web pages of a single website. ASP.Net master pages are created to take care of deficiency in .NET.

In a website, you can find number of features same across multiple web pages of a single website such as copyright notices, menus, logos etc. Also, a website has a single layout design. Sometimes, even the control buttons across the web pages remains same. In such condition, Master pages take the control to apply same features across the multiple web pages.

Usually, the master page is differentiated by @Master directive which takes place of the directive @page which is used in the pages which are not the part of master pages. The master directive looks something like below:

<%@ Master Language="VB" %>

The directive @Master can contain almost the same directives which @Control directive can. I.e. below master page directive contains the name of the code file and allocates a class name for the master page.

<%@ Master Language="VB" CodeFile="MasterPageexam.masterexam.vb" Inherits="MasterPageexam" %>

In addition to above elements, @Master directive can also contains the top level HTML elements such as head, html tag, form tag etc. for a web page. I.e. user can use the html table tag and image tag to include table and image in the web page. User is allowed to use all the elements of ASP.NET and HTML as a part of the master page. This means ASP.NET master page is a well organized feature for the ASP.NET users to have same look and feel across multiple web pages with a little effort.

 

For Step 5 please click here.

Tags:

Coding

Step3: ASP.NET Web User Controls

by Jane Thomson 19. March 2011 01:05

We will learn about new control which is known as web user controls in step 3. Web User controls are the controls which are created and added to the web pages. To create a web user control on the web page is pretty much similar to creating a control for the desktop applications. The user control is ASP.NET is based in the class System.Web.UI.UserControl.

Adding a Web User Control on a web page is pretty simple. You can add user controls from the user Add Controls Windows of ASP.NET and by default they come with the .ascx extension. Instead of having @page directives, ASP.NET user controls contain @control directive which defines the configuration of the user control. The limitation of Web User Control is that they cannot be used stand alone and user must have to add it into the ASP.NET webpage just like other controls. ASP.NET web user control differs from the traditional web user control in a way that they shall have the elements like html, body or form only on the hosting page.

Add Web User Controls to Page

In order to add ASP.NET web user controls to the page, user must have to register it on hosting page. While registering, user has to denote the.ascx file containing web user control, a tag name and a tag prefix.

Once done with registering the control, user has to add the code for putting the control on the host page. In this case, below line of code is useful.

<uc1:links id="links1" runat="server"/>

Just like other controls on the page, you can see that even web user controls contains the property of runat = “server” which defines its dynamic nature on ASP.NET unlike traditional web user controls. If a web user control has the Web Server Control, you can also code a web user control to handle events requested by other child web user controls.

For Step 4 please click here.


Tags:

Step2: Using HTML Server Controls in ASP.NET

by Jane Thomson 19. March 2011 01:04

Let us look at the second step of learning ASP.NET which is about learning HTML Server Controls. HTML Server Controls are just like HTML tags of old time with an additional attribute of “runat” which provides the functionality to run the control at server. This attribute gives ASP.NET control an advantage over the old age HTML controls, which allows the programmers to use it programmatically. i.e. If there exist <a> in a web page and it needs to be used dynamically with changing the address, the attribute runat = “server” can help to achieve this.

For almost all HTML elements, the server side HTML control exists. It’s pretty easy to create the HTML server control. It just requires applying the attribute runat=”server” in the regular HTML tag and it will create HTML controlled version for this tag. The HTML server controls have been contained inside the namespace System.Web.UI.HtmlControls. Because of the fact that the HTML server controls have been handled at the server side in the ASP.NET runtime, their properties can also be accessed somewhere else in the webpage through the programming. If you might have worked either with CSS, HTML or JavaScript, you might know how error-prone and cumbersome it can be to manipulate the inline styles and text within the HTML tags. HTML Server controls on the ASP.NET aims to resolve this issue by allowing to manipulate the data quickly with any of the NET languages.

Let us look at few control classes of HTML that uses the “runat” server attribute.

  1.     HTMLForm
  2.     HTMLButton
  3.     HTMLAnchor
  4.     HTMLImage
  5.     HTMLInputButton
  6.     HTMLInputImage
  7.     HTMLTable
  8.     HTMLInputText
  9.     HTMLTextArea
  10.   HTMLGenericControl

So, as described in this page, it’s really easy to use the HTML Server controls with the ASP.NET which will provide user an advantage of accessing HTML Server Controls through the programming.

 

For Step 3 please click here.

Tags:

Step1: Create a Web Form

by Jane Thomson 1. February 2011 13:05

Just like any other technology, you will also find new terminologies in the ASP.NET as well. For a practical example, the word used to mention the web page is ASP.NET is known as a web form and it is the most important terminology of ASP.NET as it’s a central object in the language of ASP.NET. At a first look, the web forms look just like static HTML pages. However, they also contain .NET specific components in addition to the HTML elements as well as some code which executes on the server’s machine.

 

Web Forms

 

Each web form contains a tag <form runat = “server”>, which holds the ASP.NET specific elements in it which makes the page. However, there is no support for multiple forms. The actual structure of a simple web form is given below:

 

<%@ Page Language="language" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.abc.com/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server"> 
… some code …

</script>

 

<html xmlns="http://www.abc.com/2003/xhtml"> 
<head runat="server"> 
 <title> Title of the Page</title> 
</head> 
<body> 
 <form id="form id" runat="server"> 
   … UI elements… 
 </form> 
</body> 
</html>

 

In order to programmatically access and change the data, the classs System.Web.UI.Page is being used. It is mandatory to define this class in the code file of a web form. In case, user is not generating a specific code file for a web form (when all the code is written in the file .aspx), the class is still gets generated, it is just that user is not able to see that.

 

In ASP.NET, wide ranges of UI elements are available to use in a web form which also includes the static HTML code. But, a user shall use the elements for which either values can be generated or changed. Such elements are known as controls in ASP.NET. There are numerous controls available in the ASP.NET as listed below:

 

  1. Master Pages
  2. Web User Controls
  3. Web Server Controls
  4. HTML Server Controls

 

We will learn about such controls in the coming chapters.

 

For Step 2 please click here.

Tags:

Brief about ASP.net Master Pages

by Jane Thomson 30. November 2010 19:04

As we all know, with the release of ASP.net 2.0, it has become quite easy to create uniform layout across almost all the pages on a website. Let us look at some brief of the ASP.net master pages here in this article.

 

In order to create uniform pages across the website, a user needs to create only one master page which can characterize the look, feel and typical behavior of all the pages across the website. After that, individual content pages can be created with the given look and feel with required content on the page. Thus, while user requests for the content page, ASP.net merges it with the master page to create a combine page of defined layout and content.

 

Just like master pages, there exists a feature called dynamic web template. However, it is advised to use master pages while using the ASP.net to give a consistent look across the website with the share content pages. And if a user is working with the HTML files, it is advisable to use the dynamic web templates.

 

Benefits of Using Master Pages

 

Let us now look at the benefits of using the master pages in the ASP.net files which can convince a user to use the master pages in website. Traditionally, it was defined to copy all the code from one page to another page in order to create uniform pages across the website but master page has overtaken this duty to make it quite simple for a user. The benefits include:

 

  1. Master page allows unifying the common functionality required in all the pages so user only has to update a single page.
  2. Master page allows to create only single set of controls which can be applied to the pages across the website.
  3. With this, it also provides such a model object through which user can modify the master page through the individual content page.

Tags: ,

Coding

ASP.net Themes and Skins

by Jane Thomson 27. October 2010 00:04

ASP.net themes are made up with the different kind of elements which includes CSS, skins, images as well as few other sources. If not anything else, themes will at least contain skins in it. The themes of ASP.net shall be defined in the particular directory for the website or on the web browser. Let us look at the skins feature of the ASP.net themes.

Skins

A skin in the ASP.net is stored with the extension .skin as a file and the file contains the different kinds of property settings for the controls such as Label, Calendar, Textbox or Command button etc. Generally, the settings of the control skin are just like control markup but only contains the properties that a user wants to set in the theme.

As said earlier, the .skin file is created under theme folder. A skin file can contain more than one control skins for more than one control. Instead, you can also define the different skins in the different file or let’s say in a separate file as well.

There are two different types of control skins, named skins and default skins. Let us look at them in details here.

1.    Default skin is the one which is applied to all the same type of controls when the theme is applied to any particular page. If the skin does not have the SkinId property, the control skin becomes the default skin. For an example, if user creates the default skin for the calendar control, it applies to calendar control on all the pages where the theme is applied.

2.    In contrary to default skin, if the control skin has a SkinId property, it is known as the named skin. This skin type is not applied to all the controls. Instead, a user has to apply named skin to the control by changing the SkinID property of the control.

Tags:

Coding

Configure ASP.NET for Membership Provider

by Jane Thomson 6. October 2010 20:54

Configure ASP.NET for Membership Provider

In order to use the membership features of ASP.NET, it is required to configure the membership features in the machine. Here are the basic steps that to follow for the same:

1.    First of all specify the options of memberships as a part of website configuration. Please specify which membership provider shall be used for the website. The provider that is available by default stores the membership details into the SQL Server database. However, there are other membership providers to use like provider from the Windows Live Id. Let us look at how we can configure Membership provider for ASP.NET web application.

2.    ASP.NET membership can be configured with the element membership located in the web.config file for the web application. In fact, the membership is a sub-element of the system.web section. It is possible to enable the ASP.NET membership directly by editing the web.config file of the web application. Even a website administration tool can be used for the same that provided the wizard based interface to configure it. To configure the membership feature, user has to specify:

a.    The membership providers to use. It also includes the database to store the membership information.

b.    Password option like encryption and whether it’s feasible to support the password recovery based on the user information.

c.    Username and Passwords. If the web administration tool has been used, users can be directly created and managed. If not, user has to call membership functions to create as well as manage the users.

3.    There is another feature with the membership provider is to select the membership provider with defaltprovider characteristic of membership element. There is a machine configuration SQLMembership Provider instance with the name “AspNetSqlMembershipProvider” which works as a default provider if the default provider hasn’t been specified. The “AspNetSqlMembershipProvider” provider is connected with the aspnetdb database in the SQL Server of the local machine. However, a user has to set up the database which is used by “SqlMembershipProvider” before it can be used in the application.

 

Specifying the Default Provider


You specify the default membership provider using the defaultProvider attribute of the membership element. The machine configuration specifies a SqlMembershipProvider instance named "AspNetSqlMembershipProvider" that is identified as the default provider if you do not specify a default provider explicitly. The "AspNetSqlMembershipProvider" connects to the aspnetdb database in the local SQL Server.

Please refer to the code below in order to check the web.config file.

<configuration>

  <connectionStrings>

    <add name="MySqlConnection" connectionString="Data

      Source=MySqlServer;Initial Catalog=aspnetdb;Integrated

      Security=SSPI;" />

  </connectionStrings>

  <system.web>

    <authentication mode="Forms" >

      <forms loginUrl="login.aspx"

        name=".ASPXFORMSAUTH" />

    </authentication>

    <authorization>

      <deny users="?" />

    </authorization>

    <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">

      <providers>

        <clear />

        <add

          name="SqlProvider"

          type="System.Web.Security.SqlMembershipProvider"

          connectionStringName="MySqlConnection"

          applicationName="MyApplication"

          enablePasswordRetrieval="false"

          enablePasswordReset="true"

          requiresQuestionAndAnswer="true"

          requiresUniqueEmail="true"

          passwordFormat="Hashed" />

      </providers>

    </membership>

  </system.web>

</configuration>

 

Tags:

Coding

ASP.NET Membership features with .net Framework 4

by Jane Thomson 6. October 2010 20:51

ASP.NET Membership features with .net Framework 4

Membership provider is a standalone feature in the ASP.NET to provide the authentication; it can easily be integrated with the role management functionality in order to provide the authorization servicing feature for the website. If needed, membership provider can also be integrated with the user profile provider in order to make available the application related customization for individual users.

The membership features can be used in order to authenticate the users either in the website or in the application built with ASP.NET. Generally, users can use membership features to provide the pages of log in such as to create a new log in or to request for the new password with forgot password page. Virtually, ASP.NET encapsulates all the required logic, prompts the users for the login details and validates the login credentials to allow the access to the membership area. In fact, default template for creating such pages includes most of these basic functionalities about login. Let’s say, if user has already created an application to use the authentication form. ASP.NET will by default display the authentication page if it is requested by the unauthenticated users.

If a user uses the login controls or project templates from the ASP.NET, membership provider to validate the user credentials will by default be used. If a user decides to use the customized login controls, it is necessary to use the validateuser method to validate the user credentials. After validating the user information, it can be stored such as encrypted cookie in user’s machine (if user’s machine allows doing so). The membership provider will automatically use this feature. However, if you are using the customized login controls, Forms Authentication control can be used to generate the cookies in order to store it into the user’s machine. The membership credentials can also provide the features to recover password with the recover password and reset password user controls.

Tags:

Coding

::: | © Malaika Consultants LLC | :::

Malaika Consultants LLC

Malaika Consultants LLC is a custom software development consulting firm located in Cary (Raleigh Durham Research Triangle AKA RTP area ) North Carolina. We offer our expert consulting services in the Microsoft .NET and related technologies. Our mission is to partner with you and ensure the success of your project. We have a team in the USA that will help you with your Information Technology needs and we strive to be truly "Your Information Technology Angels"

We are offering 1 hour of free consulting -- ASP.NET, SQL Server, IIS, anything. Contact us to get your free consulting

Recent Comments

Comment RSS