Category Archives: asp.net in c#

Different Types of Themes

An ASP.NET page has two different properties that enable you to set a theme: the Theme property and the StyleSheetTheme property. Both of these properties use the themes that you define in the App_Themes folder. Although at first they seem very similar, it’s their runtime behavior that makes the difference. The StyleSheetTheme is applied very early in the page’s life cycle, shortly after the page instance has been created. This means that an individual page can override the settings from the theme by applying inline attributes on the controls. So, for example, a theme with a skin file that sets the BackColor of a button to purple can be overridden by the following control declaration in the markup of the page:
<asp:Button ID=”Button1” runat=”server” Text=”Button” BackColor=”Red” />
The theme in the Theme property, on the other hand, is applied late in the page’s life cycle, effectively overriding any customization you may have for individual controls.

ASP.NET Page Life Cycle

  • Page request A request to an ASPX page starts the life cycle of that page. When the web server is able and allowed to return a cached copy of the page, the entire life cycle is not executed. In all other situations, the page enters the start phase.
  • Start In this phase, the page gets access to properties like Request and Response that are used to interact with the page’s environment. In addition,during this phase the PreInit event is raised to signal that the page is about to go into the initialization phase.
  • Page initialization During this phase, the controls you have set up in your page or added programmatically become available. Additionally, the Page class fires three events: Init, InitComplete, and PreLoad. Also during this phase, the control properties are loaded from View State and Control State again during a postback. So, for example, when you change the selected item in a DropDownList and then cause a postback, this is the moment where the correct item gets preselected in the drop-down list again, which you can then work with in your server-side code.
  • Load During this phase the page raises the Load event.
  • Validation In the validation phase, the Validation controls used to validate user input are processed.
  • Postback event handling During this phase, the controls in your page may raise their own events. For example, the DropDownList may raise a SelectedIndexChanged event when the user has chosen a different option in the list. Similarly, a TextBox may raise the TextChanged event when the user has changed the text before she posted back to the server. When all event processing is done, the page raises the LoadComplete event. During this phase the PreRender event is raised to signal that the page is about to render to the browser. Shortly after that, SaveStateComplete is raised to indicate that the page is done storing all the relevant data for the controls in View State.
  • Rendering Rendering is the phase where the controls (and the page itself) output their HTML to the browser.
  • Unload The unload phase is really a clean-up phase. This is the moment where the page and controls can release resources like database connections.During this phase, the Unload event is raised so you can handle any cleanup you may need to do.

Assign a page as the start page in asp.net

You can assign a page as the start page by right-clicking it in the Solution Explorer and choosing Set As Start Page. If you want to control this behavior at a later stage, right-click the web site in the Solution Explorer and choose Property Pages. In the Start Options category, you can indicate that you want the currently active page to open, or you can assign a specific page, as show

Image

Code Files and Data Files

Code Files

  • Web Service .asmx Can be called by other systems, including browsers, and can contain code that can be executed on your server.
  • Class .cs Can contain code to program your web site.
  • Global Application Class .asax Can contain code that is fired in response to interesting things that happen in your site, such as the start of the application or when an error occurs somewhere in the site.

Data Files

  • XML File .xml Used to store data in XML format. In addition to plain XML files, ASP.NET supports a few more XML-based files, two of which you briefly saw before: web.config and the Site Map.
  • SQL Server Database .mdf Files with an .mdf extension are databases that are used by Microsoft SQL Server.
  • ADO.NET Entity Data Model .dbml Used to access databases declaratively, without the need to write code. Technically, this is not a data file, because it does not contain the actual data. However, because it is tied to the database so closely, it makes sense to group it under this header.

Web Files

Web Files are specific to web applications and can either be requested by a browser directly, or are used to build up part of the web page that is requested in the browser. The following table lists the various web files and their extensions, and describes how each file is used.

  • Web Form .aspx The workhorses of any ASP.NET web site, Web Forms represent the pages that your users view in their browser.
  • Master Page .master Enable you to define the global structure and the look and feel of a web site.
  • Web User Control .ascx Contains page fragments that can be reused in multiple pages in your site.
  • HTML Page .htm / .html Can be used to display static HTML in your web site.
  • Style Sheet .css Contains CSS code that enables you to style and format your web site. 
  • Web Configuration File .config Contains global configuration information that is used throughout the site.
  • Site Map .sitemap Contains a hierarchical representation of files in your site in an XML format.
  • JScript File .js Contains JavaScript (which Microsoft calls JScript) that can be executed in the client’s browser.
  • Skin File .skin Contains design information for controls in your web site.