私の仕事は2つのページを1つにマージすることです。私はASP.NETで動作します。読み込み中は、.cssとビジネスオブジェクトを選択し、asp:updatePanelでデータを入力する必要があります。両方のサイトは、2つの異なるデバイスからのログを表示する必要があります。スタイルシートを動的に切り替える
私が理解するように、私はPage_Loadのすべてを切り替える必要があります。
私は同じ時間でPage_PreIntとのPage_LoadでCSSファイルを選択しようとした、およびそれらのどちらも働いた:
protected void Page_PreInit(object sender, EventArgs e)
{
// seting the master page
switch (deviceOrTerminal)
{
case DeviceOrTerminalEnum.Device:
this.Master.MasterPageFile = "~/Device/Device.Master";
Session.Add("style", "/Theme/DeviceEventHistory.css");
lnkCSS.Attributes["href"] = "/Theme/DeviceEventHistory.css";
lnkCSS.Attributes["href"] = "~/Theme/DeviceEventHistory.css";
break;
case DeviceOrTerminalEnum.Terminal:
this.Master.MasterPageFile = "~/Terminal/TerminalDetail.Master";
Session.Add("style", "/Theme/TerminalEventHistory.css");
lnkCSS.Attributes["href"] = "/Theme/TerminalEventHistory.css";
lnkCSS.Attributes["href"] = "~/Theme/TerminalEventHistory.css";
break;
case DeviceOrTerminalEnum.None:
this.Master.MasterPageFile = "~/Main.Master";
Session.Add("style", "/Theme/NoneEventHistory.css");
lnkCSS.Attributes["href"] = "/EventHistory/Theme/NoneEventHistory.css";
lnkCSS.Attributes["href"] = "~/EventHistory/Theme/NoneEventHistory.css";
break;
}
}`
protected void Page_Load(object sender, EventArgs e)
{
CommandBarTop.TitleCaption = TitleCaption;
CommandBarGridTop.DisableAllButtons();
CommandBarGridBottom.DisableAllButtons();
CommandBarTop.DisableAllButtons();
CommandBarBottom.DisableAllButtons();
CommandBarBottom.SetSearchMode(eventHistoryBo.PermissionId);
CommandBarBottom.SearchClicked += CommandBar_SearchClicked;
CommandBarBottom.SearchButtonText = (String)GetLocalResourceObject("CommandBar.SearchButton");
CommandBarTop.SetSearchMode(eventHistoryBo.PermissionId);
CommandBarTop.SearchClicked += CommandBar_SearchClicked;
CommandBarTop.SearchButtonText = (String)GetLocalResourceObject("CommandBar.SearchButton");
String shortDatePattern = PreferredBrowserLanguage.DateTimeFormat.ShortDatePattern;
String shortTimePattern = PreferredBrowserLanguage.DateTimeFormat.ShortTimePattern;
txtEventTimeFrom.CalendarDateFormat = shortDatePattern + " " + shortTimePattern;
txtEventTimeTo.CalendarDateFormat = shortDatePattern + " " + shortTimePattern;
String jsValidatorName = "clientValidate";
Type jsType = GetType();
if (!Page.ClientScript.IsClientScriptBlockRegistered(jsValidatorName))
{
Initialize();
if (!Page.IsPostBack)
{
if ((!TMSPrincipal.IsPermissionOk(deviceBo.PermissionId, EnumPermissionType.View))
|| (!TMSPrincipal.IsPermissionOk(terminalBo.PermissionId, EnumPermissionType.View)))
{
throw new HttpException("Insufficient permissions to view details.");
}
switch (deviceOrTerminal)
{
case DeviceOrTerminalEnum.Device:
CommandBarTop.TitleCaption.Replace(CommandBarTop.TitleCaption.ToString(), "Device");
CommandBarGridTop.TitleCaption = "Device";
lnkCSS.Attributes["href"] = "/Theme/DeviceEventHistory.css";
lnkCSS.Attributes["href"] = "~/Theme/DeviceEventHistory.css";
break;
case DeviceOrTerminalEnum.Terminal:
CommandBarTop.TitleCaption.Replace(CommandBarTop.TitleCaption.ToString(), "Terminal");
CommandBarGridTop.TitleCaption = "Terimal";
lnkCSS.Attributes["href"] = "/Theme/TerminalEventHistory.css";
lnkCSS.Attributes["href"] = "~/Theme/TerminalEventHistory.css";
break;
case DeviceOrTerminalEnum.None:
CommandBarTop.TitleCaption.Replace(CommandBarTop.TitleCaption.ToString(), " ");
UserHints.Add(new UserHint(GetLocalResourceObject("Error_DeviceNorTerminal_Title.Text").ToString(), GetLocalResourceObject("Error_DeviceNorTerminal_Body.Text").ToString(), EnumUserHintType.Error));
lnkCSS.Attributes["href"] = "/EventHistory/Theme/NoneEventHistory.css";
lnkCSS.Attributes["href"] = "~/EventHistory/Theme/NoneEventHistory.css";
break;
}
txtEventTimeFrom.Text = DateTime.Now.Date.AddDays(-7).ToString("g");
txtEventTimeTo.Text = DateTime.Now.Date.AddDays(1).ToString("g");
FillData();
InitializeDropDownEventType();
}
}
}
私は私が働いていた(前の1ヶ月間、ASP.NETのこの種のプログラミングをしていますMVCとRazorを使用しているので)、私はどんなサービスにも感謝しています。私はいくつかの疑似質問があることを知っていますが、それらのどれも私の問題を解決しません。
を使用して、そのタスクを達成する方法をVisual Studioで、と見ます? – Jamiec
私はそれらがうまくいくと思ったが、didntだった。 –
この質問をご覧くださいhttps://stackoverflow.com/questions/19023923/how-to-render-css-conditionally-in-page –