custommodule.cs

来自「非常不错的学校在线考试分析系统」· CS 代码 · 共 84 行

CS
84
字号
namespace ASPNET.StarterKit.Communities {

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web;
    using ASPNET.StarterKit.Communities;



    //*********************************************************************
    //
    // CustomModule Class
    //
    // Displays a user control (.ascx file) in the content area of
    // a community page. 
    //
    //*********************************************************************

    [ParseChildren(true)]
    public class CustomModule : WebControl, INamingContainer {



        //*********************************************************************
        //
        // CreateChildControls Method
        //
        // Loads user control into Controls collection. The user control
        // must be located at the following path:
        //
        //   ~/Communities/[communityName]/CustomModules/[sectionName].ascx
        //
        //*********************************************************************
    
        protected override void CreateChildControls() {
            string skinFileName;
            Control skin;
            

            // Determine skin file name
            CommunityInfo objCommunityInfo = (CommunityInfo)HttpContext.Current.Items[ "CommunityInfo" ];
            SectionInfo objSectionInfo = (SectionInfo)HttpContext.Current.Items[ "SectionInfo" ];
            skinFileName = String.Format( "{0}/Communities/{1}/CustomModules/{2}.ascx", CommunityGlobals.AppPath, objCommunityInfo.Name, objSectionInfo.Name );
 

            try {

                skin = Page.LoadControl(skinFileName);
                Controls.Add(skin);
            } 

            // Catch errors so they can be displayed.

            catch (HttpException he) {

                Controls.Add(new LiteralControl(he.GetHtmlErrorMessage()));
                Context.Trace.Warn( "community error","HttpException ::",he);
            }
            catch (System.IO.FileNotFoundException fnf) {
                string errorMessage = fnf.Message+" Not Found";
                Controls.Add( new LiteralControl(errorMessage) );
                Context.Trace.Warn("community error",errorMessage,fnf);
            }
            // guess that the file was not found?
            catch (Exception e)  {
                string errorMessage = "An unknown exception caused static page ("+skinFileName+") load abort -- see trace file for more info";

            Controls.Add( new LiteralControl( errorMessage ) );
            Context.Trace.Warn( "community error", errorMessage, e);
          }



            
            
            
            
        }


    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?