System.Web.UI.WebControls.TreeView.OnPreRender C# (CSharp) Method

OnPreRender() protected method

protected OnPreRender ( EventArgs e ) : void
e EventArgs
return void
		protected internal override void OnPreRender (EventArgs e)
		{
			base.OnPreRender (e);

			Page page = Page;
			if (page != null) {
				if (IsEnabled)
					page.RegisterRequiresPostBack (this);
			
				if (EnableClientScript && !page.ClientScript.IsClientScriptIncludeRegistered (typeof(TreeView), "TreeView.js")) {
					string url = page.ClientScript.GetWebResourceUrl (typeof(TreeView), "TreeView.js");
					page.ClientScript.RegisterClientScriptInclude (typeof(TreeView), "TreeView.js", url);
				}
			}
			
			string ctree = ClientID + "_data";
			StringBuilder script = new StringBuilder ();
			script.AppendFormat (_OnPreRender_Script_Preamble,
					     ctree,
					     ClientScriptManager.GetScriptLiteral (ClientID),
					     ClientScriptManager.GetScriptLiteral (UniqueID),
					     ClientScriptManager.GetScriptLiteral (ShowExpandCollapse));			
			
			if (ShowExpandCollapse) {
				ImageStyle imageStyle = GetImageStyle ();
				script.AppendFormat (_OnPreRender_Script_ShowExpandCollapse,
						     ctree,
						     ClientScriptManager.GetScriptLiteral (GetNodeImageUrl ("plus", imageStyle)),
						     ClientScriptManager.GetScriptLiteral (GetNodeImageUrl ("minus", imageStyle)));
						     
				if (PopulateNodesFromClient)
					script.AppendFormat (_OnPreRender_Script_ShowExpandCollapse_Populate,
							     ctree,
							     ClientScriptManager.GetScriptLiteral (GetNodeImageUrl ("noexpand", imageStyle)));
			}

			if (page != null) {
				script.AppendFormat (_OnPreRender_Script_PopulateCallback,
						     ctree,
						     page.theForm,
						     page.WebFormScriptReference);
				
						     // Page.ClientScript.GetCallbackEventReference (
						     // 	     "this.uid", "nodeId",
						     // 	     "TreeView_PopulateCallback",
						     // 	     "this.treeId + \" \" + nodeId", "TreeView_PopulateCallback", false));
				
				script.AppendFormat (_OnPreRender_Script_CallbackOptions,
						     ctree,
						     ClientScriptManager.GetScriptLiteral (PopulateNodesFromClient),
						     ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (true, null)),
						     ClientScriptManager.GetScriptLiteral (GetNodeImageToolTip (false, null)));
				
				if (!page.IsPostBack)
					SetNodesExpandedToDepthRecursive (Nodes);

				bool enableClientScript = EnableClientScript;
				if (enableClientScript) {
					page.ClientScript.RegisterHiddenField (ClientID + "_ExpandStates", GetExpandStates ());

					// Make sure the basic script infrastructure is rendered
					page.ClientScript.RegisterWebFormClientScript ();
				}

				if (enableClientScript && PopulateNodesFromClient)
					page.ClientScript.RegisterHiddenField (ClientID + "_PopulatedStates", "|");

				EnsureStylesPrepared ();

				if (hoverNodeStyle != null) {
					if (page.Header == null)
						throw new InvalidOperationException ("Using TreeView.HoverNodeStyle requires Page.Header to be non-null (e.g. <head runat=\"server\" />).");
					RegisterStyle (HoverNodeStyle, HoverNodeLinkStyle);
					script.AppendFormat (_OnPreRender_Script_HoverStyle,
							     ctree,
							     ClientScriptManager.GetScriptLiteral (HoverNodeStyle.RegisteredCssClass),
							     ClientScriptManager.GetScriptLiteral (HoverNodeLinkStyle.RegisteredCssClass));					
				}
				
				page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script.ToString (), true);
				script = null;
			}
		}