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)