⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sitesettings.ascx.cs

📁 三层架构的.net源码三层架构的.net源码
💻 CS
字号:
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace MyStarterKit.Portal.Web
{
	/// <summary>
	///	SiteSettings 的摘要说明。
	///	设置站点信息的管理模板控件
	/// </summary>
	public class SiteSettings : PortalModuleControl
	{
		protected System.Web.UI.WebControls.TextBox siteName;
		protected System.Web.UI.WebControls.CheckBox showEdit;
		protected System.Web.UI.WebControls.LinkButton applyBtn;

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Verify that the current user has access to access this page
			// 用户角色为Admins的才能访问该管理模块,否则重定向到EditAccessDenied.aspx
			if (PortalSecurity.IsInRoles("Admins") == false) 
			{
				Response.Redirect("~/Admin/EditAccessDenied.aspx");
			}

			// If this is the first visit to the page, populate the site data
			// 首次加载时,从HttpContext中获取全局设置对象,给控件赋初值
			if (!Page.IsPostBack) 
			{

				// Obtain PortalSettings from Current Context
				//从HttpContext中获取全局设置对象
				PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
				//赋初值
				siteName.Text = portalSettings.PortalName;					//站点名称
				showEdit.Checked = portalSettings.AlwaysShowEditButton;		//是否总是显示编辑按钮
			}

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		设计器支持所需的方法 - 不要使用代码编辑器
		///		修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.applyBtn.Click += new System.EventHandler(this.applyBtn_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		//提交更改
		private void applyBtn_Click(object sender, System.EventArgs e)
		{
			// Obtain PortalSettings from Current Context
			//从HttpContext中获取全局设置对象
			PortalSettings portalSettings = (PortalSettings) Context.Items["PortalSettings"];
			//更新站点信息
			Configuration config = new Configuration();
			config.UpdatePortalInfo(portalSettings.PortalId, siteName.Text, showEdit.Checked);
			//重定向到当前请求的原始Url
			Response.Redirect(Request.RawUrl);        
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -