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

📄 defaultcs.aspx.cs

📁 Telerik是很大的第三方软件制造商
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Telerik.CallbackExamplesCSharp.Functionality.LoadingUserControls
{
	/// <summary>
	/// Summary description for MainPage.
	/// </summary>
	public class MainPage : System.Web.UI.Page
	{
		protected Telerik.WebControls.CallbackLinkButton lbLogin;
		protected Telerik.WebControls.CallbackLinkButton lbSearch;
		protected Telerik.WebControls.CallbackLinkButton lbTasks;
		protected Telerik.WebControls.CallbackPanel CallbackPanel1;
		protected Telerik.WebControls.LoadingPanel LoadingPanel1;
			
		private void Page_Load(object sender, System.EventArgs e)
		{								
			if (LatestLoadedControlName != null)
			{
				LoadUserControl(LatestLoadedControlName);
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.lbLogin.Click += new System.EventHandler(this.lbLogin_Click);
			this.lbSearch.Click += new System.EventHandler(this.lbSearch_Click);
			this.lbTasks.Click += new System.EventHandler(this.lbTasks_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void lbLogin_Click(object sender, System.EventArgs e)
		{
			LoadUserControl("Login.ascx");
		}

		public void LoadUserControl(string controlName)
		{
			if (LatestLoadedControlName != null)
			{
				Control previousControl = CallbackPanel1.FindControl(LatestLoadedControlName.Split('.')[0]);
				if (previousControl != null)
				{
					this.CallbackPanel1.Controls.Remove(previousControl);
				}
			}
			string userControlID = controlName.Split('.')[0];
			Control targetControl = CallbackPanel1.FindControl(userControlID);
			if (targetControl == null)
			{
				UserControl userControl = (UserControl) this.LoadControl(controlName);
				userControl.ID = userControlID;
				this.CallbackPanel1.Controls.Add(userControl);
				LatestLoadedControlName = controlName;
			}
		}

		private void lbSearch_Click(object sender, System.EventArgs e)
		{
			if (!Logged)
			{
				CallbackPanel1.Controls.Clear();
				CallbackPanel1.Controls.Add(new LiteralControl("To access this control you have to log in."));
			}
			else
			{
				LoadUserControl("Search.ascx");
			}
		}

		private void lbTasks_Click(object sender, System.EventArgs e)
		{
			if (!Logged)
			{
				CallbackPanel1.Controls.Clear();
				CallbackPanel1.Controls.Add(new LiteralControl("To access this control you have to log in."));
			}
			else
			{
				LoadUserControl("Tasks.ascx");
			}		
		}

		public bool Logged
		{
			get
			{			
				return (ViewState["Logged"] == null) ? false : (bool) (ViewState["Logged"]);
			}
			set
			{
				ViewState["Logged"] = value;
			}
		}

		private string LatestLoadedControlName
		{
			get
			{
				return (string) ViewState["LatestLoadedControlName"];
			}
			set
			{
				ViewState["LatestLoadedControlName"] = value;
			}		
		}

		public DataTable TasksTable
		{
			get
			{
				return (DataTable) ViewState["TasksTable"];
			}
			set
			{
				ViewState["TasksTable"] = value;
			}
		}

		public DataTable Tasks
		{
			get
			{
				DataTable dataTable = new DataTable();
				if (ViewState["Tasks"] == null)
				{					
					dataTable.Columns.Add("TaskName", typeof(string));
					dataTable.Columns.Add("Status", typeof(bool));

					dataTable.Rows.Add(new Object[] {"Task1", false});
					dataTable.Rows.Add(new Object[] {"Task2", true});
					dataTable.Rows.Add(new Object[] {"Task3", false});
					dataTable.Rows.Add(new Object[] {"Task4", true});
					dataTable.Rows.Add(new Object[] {"Task5", false});
					
					ViewState["Tasks"] = dataTable;
				}
				else
				{
					dataTable = (DataTable) ViewState["Tasks"];	
				}				
				return dataTable;
			}
			set
			{
				ViewState["Tasks"] = value;
			}
		}				
	}
}

⌨️ 快捷键说明

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