动态改变Style【例如动态改变Master Page,改变Butonn Text】
更多了解,可以访问这里。
通常我们都在Page_Preinit 事件中动态改变MasterPageFile的值.
通常我们都在Page_Preinit 事件中动态改变MasterPageFile的值.
void Page_PreInit(Object sender, EventArgs e) {
if (Request.Browser.IsBrowser("IE")) {
this.MasterPageFile = "ArticleMaster_IE.master";
}
else if (Request.Browser.IsBrowser("Mozilla")) {
this.MasterPageFile = "ArticleMaster_FireFox.master";
}
else {
this.MasterPageFile = "ArticleMaster.master";
}
}
但是我们可以以声明的方式实现同样功能if (Request.Browser.IsBrowser("IE")) {
this.MasterPageFile = "ArticleMaster_IE.master";
}
else if (Request.Browser.IsBrowser("Mozilla")) {
this.MasterPageFile = "ArticleMaster_FireFox.master";
}
else {
this.MasterPageFile = "ArticleMaster.master";
}
}
<%@ Page MasterPageFile="~/ArticleMaster.master"
ie:MasterPageFile="~/ArticleMaster_IE.master"
mozilla:MasterPageFile="~/ArticleMaster_FireFox.master" %>
同样ie:MasterPageFile="~/ArticleMaster_IE.master"
mozilla:MasterPageFile="~/ArticleMaster_FireFox.master" %>
<asp:button id="Button1"
ie:text="Push me you IE user"
mozilla:text="Push me you FireFox user"
text="Push me you -- you are running neigher IE or Safari"
runat="server"/>
ie:text="Push me you IE user"
mozilla:text="Push me you FireFox user"
text="Push me you -- you are running neigher IE or Safari"
runat="server"/>