动态装载

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

1: 基类 SkinnedForumWebControl : WebControl, InamingContainer

1) 默认构造函数

public SkinnedForumWebControl() {

// Attempt to get the current user

user = Users.GetLoggedOnUser();

// Is the user not availabe - must be anonymous

if (user == null)

Users.TrackAnonymousUsers();

// Set the siteStyle for the page

if (user != null)

skinName = user.Skin;

else

skinName = Globals.Skin;

// If we have an instance of context, let's attempt to

// get the ForumID so we can save the user from writing

// the code

if (null != Context) {

GetPostIDFromRequest();

GetForumIDFromRequest();

GetForumGroupIDFromRequest();

GetReturnURLFromRequest();

}

}

2) 4个自定义的方法

// Retrieves the PostID,ForumID,ForumGroupID, ReturnUrl from the request querystring/post.

private void GetPostIDFromRequest()

private void GetForumIDFromRequest()

private void ForumGroupID ()

private void GetReturnURLFromRequest ()

3) 重写方法

protected override void CreateChildControls() {

Control skin;

// Load the skin(.ascx) as an object instance

skin = LoadSkin();

// to be overrided , Initialize the control template and populate the control with values

InitializeSkin(skin);

Controls.Add(skin);

}

4) 属性访问器…

2: 继承的类

1) 属性

// Assign a default template name

string skinFilename = "Skin-Login.ascx";

// controls in (.ascx) template

TextBox username;

TextBox password;

Button loginButton;

CheckBox autoLogin;

2) 构造函数

public Login() : base() {

// Assign a default template name

if (SkinFilename == null)

SkinFilename = skinFilename;

}

3) 重写2个基类方法

protected override void CreateChildControls() {

// If the user is already authenticated we have no work to do

if (Page.Request.IsAuthenticated)

return;

base.CreateChildControls();

}

override protected void InitializeSkin(Control skin) {

// Find the login button

loginButton = (Button) skin.FindControl("loginButton");

loginButton.Click += new System.EventHandler(LoginButton_Click);

// add more ……

}

4) 自定义控件方法

public void LoginButton_Click(Object sender, EventArgs e)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航