asp.net 2.0 的aster Page主题以及皮肤的用、 成员管理、新控件
编程方式 改变页面的皮肤 示例如下:
Page.Theme = Server.HtmlEncode(Request.QueryString("Theme"))
<a href="CodeTheme.aspx?Theme=ThemeA">Theme A</a>
<a href="CodeTheme.aspx?Theme=ThemeB">Theme B</a>
<%@ Page Language="VB" Theme="Theme1" %> 在页面的前面设置Theme 来引用皮肤
定义SkinID
<%@ Page Language="VB" Theme="Theme2" %> Theme2 下面有不同的Skin 需要定义id
<asp:Label ID="Label2" runat="server" Text="Hello 2" SkinID="Blue" /><br />
<asp:label runat="server" font-bold="true" forecolor="orange" />
<asp:label runat="server" SkinID="Blue" font-bold="true" forecolor="blue" />
如果使用了theme定义了一个页面的theme ,页面中对控件的属性设置就会失效,如果希望属性设置有效 就需要用 StyleSheetTheme代替theme
<%@ Page Language="VB" StyleSheetTheme="Theme2" %>
定义节日
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
holidays(8, 15) = "反法西斯战争胜利60周年纪念日"
End Sub
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
Dim d As CalendarDay
Dim c As TableCell
d = e.Day
c = e.Cell
If d.IsOtherMonth Then
c.Controls.Clear()
Else
Try
Dim Hol As String = holidays(d.Date.Month, d.Date.Day)
If Hol <> "" Then
c.Controls.Add(New LiteralControl("<br><font color=red>" + Hol + "</font>"))
End If
Catch exc As Exception
Response.Write(exc.ToString())
End Try
End If
End Class
在整个站点中应用母版页:
<configuration>
<system.web>
<pages masterPageFile="~/Site.master" />
</system.web>
</configuration>
动态应用母版页:
void Page_PreInit (Object sender, EventArgs e)
{
Page.MasterPageFile = "~/Site.master";
}
操作母版页中的控件 (弱类型)
<asp:Label ID="Title" RunAt="server" />
((Label) Master.FindControl ("Title")).Text = "Orders";
操作母版页中的控件 (强类型)
.
<script language="C#" runat="server">
public string TitleText
get { return Title.Text; }
set { Title.Text = value; }
</script>
Master.TitleText = "Orders";
母版页可以嵌套使用
嵌套的母版页只能含有Content控件,但Content控件本身可以再嵌套 ContentPlaceHolders控件
<!-- Orders.Master -->
<%@ Master MasterPageFile="~/Site.Master" %>
<asp:Content ContentPlaceHolderID="..." RunAt="server">
<asp:ContentPlaceHolder ID="..." RunAt="server">
...
</asp:ContentPlaceHolder>
<asp:Content>
将EnableTheming属性设置为false可以为单独的控件或者整个页面禁止主题功能
<asp:DropDownList ID="Countries" EnableTheming="false" RunAt="server" />
FileUpload控件
<asp:FileUpload ID="UploadControl" RunAt="server" />
<asp:Button Text="Upload" OnClick="OnUpload" RunAt="server" />
void OnUpload (Object sender, EventArgs e)
if (FileUploadControl.HasFile) {
string name = UploadControl.PostedFile.FileName; // Path name
Stream bits = UploadControl.PostedFile.InputStream; // Contents
...
// Use the SaveAs method to persist to a local file
FileInfo file = new FileInfo (UploadControl.PostedFile.FileName);
UploadControl.SaveAs (Server.MapPath ("~/Uploads/" + file.Name);
}
MultiView控件
<asp:MultiView ID="Main" ActiveViewIndex="0" RunAt="server">
<asp:View RunAt="server">
</asp:View>
</asp:MultiView>
void OnSwitchView (Object sender, EventArgs e)
Main.ActiveViewIndex = 1; // Switch views
多国语言的支持,获取浏览器的当前语言设置 CultureInfo.CurrentCulture.Name方法可以
获得当前使用的系统
本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/10/251589.html,如需转载请自行联系原作者