温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:MyWebPages51aspx汉化最终版
1//=============================================================================================== 2
// 3
// (c) Copyright Microsoft Corporation. 4
// This source is subject to the Microsoft Permissive License. 5
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. 6
// All other rights reserved. 7
// 8
//=============================================================================================== 9
10
using System; 11
using System.Data; 12
using System.Configuration; 13
using System.Web; 14
using System.Web.Security; 15
using System.Web.UI; 16
using System.Web.UI.Design; 17
using System.Web.UI.WebControls; 18
using System.Web.UI.WebControls.WebParts; 19
using System.Web.UI.HtmlControls; 20
using System.ComponentModel; 21
22
namespace MyWebPagesStarterKit.Controls 23
{ 24
[Designer(typeof(TemplatedContentDesigner)), ToolboxData("<{0}:TemplatedPanel runat=server></{0}:TemplatedPanel>")] 25
public class TemplatedContent : WebControl, INamingContainer 26
{ 27
private ITemplate _template; 28
29
public TemplatedContent() { } 30
31
[Browsable(false), PersistenceMode(PersistenceMode.InnerProperty)] 32
public ITemplate ContentTemplate 33
{ 34
get 35
{ 36
return _template; 37
} 38
set 39
{ 40
_template = value; 41
} 42
} 43
44
protected override void CreateChildControls() 45
{ 46
if (_template != null) 47
{ 48
PlaceHolder ctl = new PlaceHolder(); 49
_template.InstantiateIn(ctl); 50
Controls.Add(ctl); 51
} 52
} 53
54
public override void RenderBeginTag(HtmlTextWriter writer) 55
{ 56
//base.RenderBeginTag(writer); 57
} 58
59
public override void RenderEndTag(HtmlTextWriter writer) 60
{ 61
//base.RenderEndTag(writer); 62
} 63
} 64
65
public class TemplatedContentDesigner : ControlDesigner 66
{ 67
TemplateGroupCollection col = null; 68
69
public override void Initialize(IComponent component) 70
{ 71
// Initialize the base 72
base.Initialize(component); 73
// Turn on template editing 74
SetViewFlags(ViewFlags.TemplateEditing, true); 75
} 76
77
// Add instructions to the placeholder view of the control 78
public override string GetDesignTimeHtml() 79
{ 80
return CreatePlaceHolderDesignTimeHtml("Click here and use the task menu to edit the template."); 81
} 82
83
public override TemplateGroupCollection TemplateGroups 84
{ 85
get 86
{ 87
if (col == null) 88
{ 89
// Get the base collection 90
col = base.TemplateGroups; 91
92
// Create variables 93
TemplateGroup tempGroup; 94
TemplateDefinition tempDef; 95
TemplatedContent ctl; 96
97
// Get reference to the component as TemplateGroupsSample 98
ctl = (TemplatedContent)Component; 99
100
// Create a TemplateGroup 101
tempGroup = new TemplateGroup("Content"); 102
103
// Create a TemplateDefinition 104
tempDef = new TemplateDefinition(this, "Content", ctl, "ContentTemplate", false); 105
106
// Add the TemplateDefinition to the TemplateGroup 107
tempGroup.AddTemplateDefinition(tempDef); 108
109
// Add the TemplateGroup to the TemplateGroupCollection 110
col.Add(tempGroup); 111
} 112
return col; 113
} 114
} 115
116
// Do not allow direct resizing unless in TemplateMode 117
public override bool AllowResize 118
{ 119
get 120
{ 121
if (this.InTemplateMode) 122
return true; 123
else 124
return false; 125
} 126
} 127
} 128
}




[Designer(
}
}