CnForum换服技术
1.基类
public abstract class SkinnedForumWebControl : Control, INamingContainer
{
string skinFilename = null;
public string SkinFilename
{
get
{
return skinFilename;
}
set
{
skinFilename = value;
}
}
public SkinnedForumWebControl()
{
}
protected override void CreateChildControls()
{
Control skin = null;
skin = LoadSkin();
InitializeSkin(skin);
Controls.Add(skin);
}
protected Control LoadSkin()
{
Control skin;
string skinPath = Globals.GetSkinPath() + "/Skins/" + SkinFilename.TrimStart('/');
skin = Page.LoadControl(skinPath);
return skin;
}
protected abstract void InitializeSkin(Control skin);
}
{
string skinFilename = null;
public string SkinFilename
{
get
{
return skinFilename;
}
set
{
skinFilename = value;
}
}
public SkinnedForumWebControl()
{
}
protected override void CreateChildControls()
{
Control skin = null;
skin = LoadSkin();
InitializeSkin(skin);
Controls.Add(skin);
}
protected Control LoadSkin()
{
Control skin;
string skinPath = Globals.GetSkinPath() + "/Skins/" + SkinFilename.TrimStart('/');
skin = Page.LoadControl(skinPath);
return skin;
}
protected abstract void InitializeSkin(Control skin);
}
2.具体个体类
public class ThreadView : SkinnedForumWebControl
{
string skinFilename = "View-Threads.ascx";
Button sortButton;
public ThreadView()
{
if (SkinFilename == null)
SkinFilename = skinFilename;
}
protected override void InitializeSkin(Control skin)
{
sortButton = (Button) skin.FindControl("SortThreadsButton");
if (sortButton != null)
{
sortButton.Text = ResourceManager.GetString("ViewThreads_SortThreads");
sortButton.Click += new EventHandler(Sort_Changed);
}
DataBind();
}
#region Events
public void Sort_Changed (Object sender, EventArgs e)
{
DataBind();
}
#endregion
#region Databinding
public override void DataBind()
{
}
#endregion
}
{
string skinFilename = "View-Threads.ascx";
Button sortButton;
public ThreadView()
{
if (SkinFilename == null)
SkinFilename = skinFilename;
}
protected override void InitializeSkin(Control skin)
{
sortButton = (Button) skin.FindControl("SortThreadsButton");
if (sortButton != null)
{
sortButton.Text = ResourceManager.GetString("ViewThreads_SortThreads");
sortButton.Click += new EventHandler(Sort_Changed);
}
DataBind();
}
#region Events
public void Sort_Changed (Object sender, EventArgs e)
{
DataBind();
}
#endregion
#region Databinding
public override void DataBind()
{
}
#endregion
}
3.提供皮肤页面View-Threads.ascx
4.控件的使用
<Forums:ThreadView runat="server"/>