Summary review about Problem.Design.Solution

<!-- add on 07/05/30 -->


 


1.  Avoid using HTML Tables to control layout
     It is highly recommended for developers to use DIVs and separate stylesheet file to define appearance and position instead of using the traditional HTML Table. CSS styles and DIVs provide greater flexibility than tables.
   



2.  Only set the MasterPageFile property in the Page_PreInit event handler to change the MasterPage dynamically
     You can only set the MasterPageFile property in this event handler because the merging of the two pages must happen very early in the page's life cycle, the Load or Init event would be too late.
     



 

3.  @MasterType directive and the appropriate solution for providing different layouts
     We can use this.Master as a reference to its master page after adding the @MasterType directive
<%@ MasterType VirtualPath="~/MasterPage.master" %> .
     Because we can't dynamically change the master page's type at runtime. For this reason we will not use different master pages to provide different layouts to the user. We can completely change the appearence of the page by applying different styles to it.



 

4.  Specify the Theme and MasterPage
   
To apply a theme to a single page, you use the Theme attribute in the @Page directive:
     <%@ Page Language="C#" Theme="NiceTheme" MasterPageFile="~/MasterPage.master" ... %>

     To apply it to all pages, you can set the theme attribute of the <pages> element in web.config, as follows:
     <pages theme="NiceTheme" masterPageFile="~/MasterPage.master" />



 

5.  DIVs properties in CSS Style
     If you don't specify an explicit width and don't use absolute positioning, a DIV will always have an implicit width of 100%.

     #loginbox
   {
      position: absolute;
      top: 16px;
      right: 10px;
      width: 180px;
      height: 80px;

      padding: 2px 2px 2px 2px;
      font-size: 9px;

   }
    
    It uses absolute positioning, its position relys on the top and right property that you specified. 



 

6.  NameSpace, Cache and Server methods in Class files
     You can add a NameSpace into a class files, then in another aspx.cs file, just simply import the namespace and directly use its methods.
     We can use such as Cache.add and Server.MapPath in an ordinary aspx.cs page. However, we have to use the HttpContext.Current.Cache and HttpContext.Current.Server.MapPath methods in a seperate cs class.
     CacheDependency can be used to cache some information until the dependent item changes.
     CacheDependency dep = new CacheDependency(themesDirPath);
     HttpContext.Current.Cache.Insert("SiteThemes", themes, dep);
     In this case, the cache 'SiteThemes' will be kept until the dependency themesDirPath changes.



 

7.  File Operation
     To operate the folders, use the Directory.GetDirectories(themeDirPath) and Path.GetFileName(xxx[i]) to retrive the folders entire physical path or the folder name.

     To manipulate the files, use the Directory.GetFile(themeDirPath) and FileInfo class to retrieve the file information such as file name, update time and so on. 



 

8.  Control.UniqueID
     We can use the Control.UniqueID to retrive the rendered control's ID even though this control is embeded in a Component such as User Control. i.e, ctl00_LoginView1_Login_UserName.



 

9.  Customize BasePage class and __EVENTTARGET
     To implement some special events in particular page, we need to customize a BasePage class, inheriting from the System.Web.UI.Page and overriding some base's events such as OnPreInit and

OnLoad events. After that, inherit this customized BasePage class in every aspx.cs page to inplement the events you specified in the BasePage class.
     We can use this.Request.Form["__EVENTTARGET"] to retrieve the ID of Control that triggerd the postback event except the Button Control and ImageButton Control (We can use another approach to check this two kinds of Controls, refer to an article posted previously) 



 


 

posted @ 2007-05-30 01:46  眼里进了砂  阅读(256)  评论(0编辑  收藏  举报