i have master page that have no panels. i would like to use facade pattern to view appropriate panel or set of panel while user clicks link button of content place holder page.
我有没有面板的母版页。我想在用户点击内容占位符页面的链接按钮时使用外观模式查看适当的面板或面板组。
while on first account load (Initial state),first panel will be visible and others are off, while user clicks link button of landing page, second panel visible and others are off.
在第一个帐户加载(初始状态)时,第一个面板将可见,其他面板关闭,而用户单击登录页面的链接按钮,第二个面板可见,其他面板关闭。
how ever i create this base class newManageClass:
我怎么创建这个基类newManageClass:
public class newManageClass : System.Web.UI.Page
{
public Panel Panel_User_Photo { get; set; }
public Panel Panel_Search { get; set; }
public Panel Panel_notification { get; set; }
public Panel Panel_companymanagement { get; set; }
public Panel Panel_omwealthmanagement { get; set; }
public Panel Panel_newsletter { get; set; }
public newManageClass()
{
Panel_User_Photo = new Panel();
Panel_Search = new Panel();
Panel_notification = new Panel();
Panel_companymanagement = new Panel();
Panel_omwealthmanagement = new Panel();
Panel_newsletter = new Panel();
}
public void OnPageLoad()
{
Panel_User_Photo.Visible = true;
Panel_Search.Visible = true;
Panel_notification.Visible = true;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
public void CompanyManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_companymanagement.Visible = true;
Panel_notification.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
public void OmWealthManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = true;
Panel_newsletter.Visible = false;
}
public void NewsLetterManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = false;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = true;
}
public void UserManagementClick()
{
Panel_User_Photo.Visible = false;
Panel_Search.Visible = true;
Panel_notification.Visible = false;
Panel_companymanagement.Visible = false;
Panel_omwealthmanagement.Visible = false;
Panel_newsletter.Visible = false;
}
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
if (Session["MyTheme"] == null)
{
Session.Add("MyTheme", "blue");
Page.Theme = ((string)Session["MyTheme"]);
}
else
{
Page.Theme = ((string)Session["MyTheme"]);
}
}
}
after all that i implement this class as helper class to master page:
毕竟我实现这个类作为母版页的辅助类:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Globalization;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Collections.ObjectModel;
using System.IO;
using System.Xml;
public partial class Admin_MasterPage : System.Web.UI.MasterPage
{
newManageClass manage_panels = new newManageClass();
DateTime LastCheck = DateTime.MinValue;
struct UnreadMails
{
//public string From { get; set; }
private string _From;
public string From
{
get { return _From; }
set { _From = value; }
}
//public string Subject { get; set; }
private string _Subject;
public string Subject
{
get { return _Subject; }
set { _Subject = value; }
}
//public DateTime MailModify { get; set; }
private DateTime _MailModify;
public DateTime MailModify
{
get { return _MailModify; }
set { _MailModify = value; }
}
}
Collection<UnreadMails> GetNewMails()
{
WebRequest webGmailRequest = WebRequest.Create(@"https://mail.google.com/mail/feed/atom");
webGmailRequest.PreAuthenticate = true;
NetworkCredential loginCredentials = new NetworkCredential("XXXXXXXXXX", "XXXXX");
webGmailRequest.Credentials = loginCredentials;
WebResponse webGmailResponse = webGmailRequest.GetResponse();
Stream strmUnreadMailInfo = webGmailResponse.GetResponseStream();
StringBuilder sbUnreadMailInfo = new StringBuilder(); byte[] buffer = new byte[8192]; int byteCount = 0;
while ((byteCount = strmUnreadMailInfo.Read(buffer, 0, buffer.Length)) > 0)
sbUnreadMailInfo.Append(System.Text.Encoding.ASCII.GetString(buffer, 0, byteCount));
XmlDocument UnreadMailXmlDoc = new XmlDocument();
UnreadMailXmlDoc.LoadXml(sbUnreadMailInfo.ToString());
XmlNodeList UnreadMailEntries = UnreadMailXmlDoc.GetElementsByTagName("entry");
UnreadMails oUnreadMails = new UnreadMails();
Collection<UnreadMails> clUnreadMails = new Collection<UnreadMails>();
for (int _i = 0; _i < UnreadMailEntries.Count; ++_i)
{
oUnreadMails.Subject = (UnreadMailEntries[_i]["title"]).InnerText;
oUnreadMails.From = (UnreadMailEntries[_i]["author"])["name"].InnerText + " <" + (UnreadMailEntries[_i]["author"])["email"].InnerText + ">";
oUnreadMails.MailModify = DateTime.Parse((UnreadMailEntries[_i]["modified"]).InnerText);
clUnreadMails.Add(oUnreadMails);
}
return clUnreadMails;
}
protected void Page_Load(object sender, EventArgs e)
{
manage_panels.Panel_User_Photo = (Panel)this.Page.Master.FindControl("Panel_User_Photo");
manage_panels.Panel_Search = (Panel)this.Page.Master.FindControl("Panel_Search");
manage_panels.Panel_notification = (Panel)this.Page.Master.FindControl("Panel_notification");
manage_panels.Panel_companymanagement = (Panel)this.Page.Master.FindControl("Panel_companymanagement");
manage_panels.Panel_omwealthmanagement = (Panel)this.Page.Master.FindControl("Panel_omwealthmanagement");
manage_panels.Panel_newsletter = (Panel)this.Page.Master.FindControl("Panel_newsletter");
string fullPath = Request.Url.AbsolutePath;
string fileName = System.IO.Path.GetFileName(fullPath);
switch (fileName)
{
case "Inquiry_history.aspx":
manage_panels.OnPageLoad();
break;
case "manage_companies.aspx":
manage_panels.CompanyManagementClick();
break;
case "service_manage.aspx":
manage_panels.OmWealthManagementClick();
break;
case "subscriber_manage.aspx":
manage_panels.NewsLetterManagementClick();
break;
case "user_manage.aspx":
manage_panels.UserManagementClick();
break;
default:
manage_panels.OnPageLoad();
break;
}
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
else
{
if (!Page.IsPostBack)
{
manage_panels.OnPageLoad();
using (SqlConnection conn = Util.GetConnection())
{
conn.Open();
string select = "SELECT COUNT(*) FROM tbl_FreeTrial_History WHERE ((MONTH(Created_date)=DATEPART(month,GETDATE()) AND DAY(Created_date)= DATEPART(day,GETDATE()) AND YEAR(Created_date)= DATEPART(year,GETDATE())))";
SqlCommand cmd = new SqlCommand(select, conn);
int nResult;
nResult = int.Parse(cmd.ExecuteScalar().ToString());
lbl_free_count.Text = nResult.ToString();
string select1 = "SELECT COUNT(*) FROM tbl_Inquiry_History WHERE IsRead='False'";
SqlCommand cmd1 = new SqlCommand(select1, conn);
int nResult1;
nResult1 = int.Parse(cmd1.ExecuteScalar().ToString());
lbl_service_count.Text = nResult1.ToString();
}
string name, email, birth_date, phone_no, address, occuption, password, city_name, pin, counry_id, state_id;
int profile_id;
DatabaseHelper.GetUserProfile(Session["username"].ToString(), out name, out profile_id, out password, out email, out phone_no, out address, out birth_date, out occuption, out counry_id, out state_id, out city_name, out pin);
lbldisplayname.Text = name;
int NewUnreadMail = 0;
DateTime LastUnreadMailDate = DateTime.MinValue;
Collection<UnreadMails> clUnreadMails = GetNewMails();
for (int i = 0; i < clUnreadMails.Count; i++)
{
if (clUnreadMails[i].MailModify > LastCheck)
{
NewUnreadMail++;
}
if (clUnreadMails[i].MailModify > LastUnreadMailDate)
LastUnreadMailDate = clUnreadMails[i].MailModify;
}
LastCheck = LastUnreadMailDate;
lblnewunreadmail.Text = NewUnreadMail.ToString();
}
}
protected void SiteMapPath1_ItemCreated(object sender, SiteMapNodeItemEventArgs e)
{
if (e.Item.ItemType == SiteMapNodeItemType.Root || (e.Item.ItemType == SiteMapNodeItemType.PathSeparator && e.Item.ItemIndex == 1))
{
e.Item.Visible = false;
}
}
protected void lbtnlogout_Click(object sender, EventArgs e)
{
Session.Clear();
Response.Redirect("../Default.aspx");
}
protected void hplhome_Click(object sender, EventArgs e)
{
Response.Redirect("Admin_Landing_page.aspx");
manage_panels.OnPageLoad();
}
}
and this is admin_landing_page.aspx code:
这是admin_landing_page.aspx代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Admin_Admin_Landing_page : newManageClass
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["username"] == null)
{
Response.Redirect("../Default.aspx");
}
else
{
OnPageLoad();
}
}
protected void lbut_manage_inquiry_Click(object sender, EventArgs e)
{
Response.Redirect("Inquiry_history.aspx");
OnPageLoad();
}
protected void lbut_company_management_Click(object sender, EventArgs e)
{
Response.Redirect("manage_companies.aspx");
CompanyManagementClick();
}
protected void lbut_stocksmanagement_Click(object sender, EventArgs e)
{
Response.Redirect("service_manage.aspx");
OmWealthManagementClick();
}
protected void lbut_newslettermanagement_Click(object sender, EventArgs e)
{
Response.Redirect("subscriber_manage.aspx");
NewsLetterManagementClick();
}
protected void lbut_usermanagement_Click(object sender, EventArgs e)
{
Response.Redirect("user_manage.aspx");
UserManagementClick();
}
}
1 个解决方案
#1
1
I am not sure if this is what you are looking for but here's what I tried
我不确定这是不是你要找的,但这就是我试过的
newManageClass.cs
using System.Web.UI.WebControls;
public class newManageClass
{
public Panel Panel1 { get; set; }
public Panel Panel2 { get; set; }
public Panel Panel3 { get; set; }
public void OnPageLoad()
{
Panel1.Visible = true;
Panel2.Visible = true;
Panel3.Visible = true;
}
public void button1()
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = false;
}
public void button2()
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
}
public void button3()
{
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
}
}
Admin_Masterpage.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Admin_MasterPage.master.cs" Inherits="Admin_MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BackColor="Red" Height="50px">abc</asp:Panel>
<asp:Panel ID="Panel2" runat="server" BackColor="Green" Height="50px">def</asp:Panel>
<asp:Panel ID="Panel3" runat="server" BackColor="Blue" Height="50px">ghi</asp:Panel>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Admin_Masterpage.master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_MasterPage : System.Web.UI.MasterPage
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["MyTheme"] == null)
{
Session.Add("MyTheme", "blue");
Page.Theme = ((string)Session["MyTheme"]);
}
else
{
Page.Theme = ((string)Session["MyTheme"]);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Admin_Landing_Page.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin_MasterPage.master" AutoEventWireup="true" CodeFile="Admin_Landing_Page.aspx.cs" Inherits="Admin_Landing_Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="btn1" runat="server" Text="Button1" OnClick="btn1_Click" />
<asp:Button ID="btn2" runat="server" Text="Button2" OnClick="btn2_Click" />
<asp:Button ID="btn3" runat="server" Text="Button3" OnClick="btn3_Click" />
</asp:Content>
Admin_Landing_Page.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_Landing_Page : System.Web.UI.Page
{
newManageClass cls = new newManageClass();
protected void Page_Load(object sender, EventArgs e)
{
cls.Panel1 = this.Page.Master.FindControl("Panel1") as Panel;
cls.Panel2 = this.Page.Master.FindControl("Panel2") as Panel;
cls.Panel3 = this.Page.Master.FindControl("Panel3") as Panel;
}
protected void btn1_Click(object sender, EventArgs e)
{
cls.button1();
}
protected void btn2_Click(object sender, EventArgs e)
{
cls.button2();
}
protected void btn3_Click(object sender, EventArgs e)
{
cls.button1();
}
}
#1
1
I am not sure if this is what you are looking for but here's what I tried
我不确定这是不是你要找的,但这就是我试过的
newManageClass.cs
using System.Web.UI.WebControls;
public class newManageClass
{
public Panel Panel1 { get; set; }
public Panel Panel2 { get; set; }
public Panel Panel3 { get; set; }
public void OnPageLoad()
{
Panel1.Visible = true;
Panel2.Visible = true;
Panel3.Visible = true;
}
public void button1()
{
Panel1.Visible = true;
Panel2.Visible = false;
Panel3.Visible = false;
}
public void button2()
{
Panel1.Visible = false;
Panel2.Visible = true;
Panel3.Visible = false;
}
public void button3()
{
Panel1.Visible = false;
Panel2.Visible = false;
Panel3.Visible = true;
}
}
Admin_Masterpage.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Admin_MasterPage.master.cs" Inherits="Admin_MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" BackColor="Red" Height="50px">abc</asp:Panel>
<asp:Panel ID="Panel2" runat="server" BackColor="Green" Height="50px">def</asp:Panel>
<asp:Panel ID="Panel3" runat="server" BackColor="Blue" Height="50px">ghi</asp:Panel>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Admin_Masterpage.master.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_MasterPage : System.Web.UI.MasterPage
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (Session["MyTheme"] == null)
{
Session.Add("MyTheme", "blue");
Page.Theme = ((string)Session["MyTheme"]);
}
else
{
Page.Theme = ((string)Session["MyTheme"]);
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Admin_Landing_Page.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin_MasterPage.master" AutoEventWireup="true" CodeFile="Admin_Landing_Page.aspx.cs" Inherits="Admin_Landing_Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Button ID="btn1" runat="server" Text="Button1" OnClick="btn1_Click" />
<asp:Button ID="btn2" runat="server" Text="Button2" OnClick="btn2_Click" />
<asp:Button ID="btn3" runat="server" Text="Button3" OnClick="btn3_Click" />
</asp:Content>
Admin_Landing_Page.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Admin_Landing_Page : System.Web.UI.Page
{
newManageClass cls = new newManageClass();
protected void Page_Load(object sender, EventArgs e)
{
cls.Panel1 = this.Page.Master.FindControl("Panel1") as Panel;
cls.Panel2 = this.Page.Master.FindControl("Panel2") as Panel;
cls.Panel3 = this.Page.Master.FindControl("Panel3") as Panel;
}
protected void btn1_Click(object sender, EventArgs e)
{
cls.button1();
}
protected void btn2_Click(object sender, EventArgs e)
{
cls.button2();
}
protected void btn3_Click(object sender, EventArgs e)
{
cls.button1();
}
}