System.Web.UI.HtmlControls.HtmlForm.RenderAttributes C# (CSharp) Method

RenderAttributes() protected method

protected RenderAttributes ( System.Web.UI.HtmlTextWriter w ) : void
w System.Web.UI.HtmlTextWriter
return void
		protected override void RenderAttributes (HtmlTextWriter w)
		{
			/* Need to always render: method, action and id
			 */
			/* The name attribute is rendered _only_ if we're not in
			   2.0 mode or if the xhtml conformance mode is set to
			   Legacy for 2.0 according to http://msdn2.microsoft.com/en-us/library/system.web.ui.htmlcontrols.htmlform.name.aspx
			*/
			
			string action;
			string customAction = Attributes ["action"];
			Page page = Page;
			HttpRequest req = page != null ? page.Request : null;
			if (req == null)
				throw new HttpException ("No current request, cannot continue rendering.");
#if !TARGET_J2EE
			if (String.IsNullOrEmpty (customAction)) {
				string file_path = req.ClientFilePath;
				string current_path = req.CurrentExecutionFilePath;
				if (file_path == current_path) {
					// Just the filename will do
					action = UrlUtils.GetFile (file_path);
				} else {
					// Fun. We need to make cookieless sessions work, so no
					// absolute paths here.
					bool cookieless;
					SessionStateSection sec = WebConfigurationManager.GetSection ("system.web/sessionState") as SessionStateSection;
					cookieless = sec != null ? sec.Cookieless == HttpCookieMode.UseUri: false;
					string appVPath = HttpRuntime.AppDomainAppVirtualPath;
					int appVPathLen = appVPath.Length;
						
					if (appVPathLen > 1) {
						if (cookieless) {
							if (StrUtils.StartsWith (file_path, appVPath, true))
								file_path = file_path.Substring (appVPathLen);
						} else if (StrUtils.StartsWith (current_path, appVPath, true))
							current_path = current_path.Substring (appVPathLen);
					}
					
					if (cookieless) {
						Uri current_uri = new Uri ("http://host" + current_path);
						Uri fp_uri = new Uri ("http://host" + file_path);
						action = fp_uri.MakeRelative (current_uri);
					} else
						action = current_path;
				}
			} else
				action = customAction;
			action += req.QueryStringRaw;
#else
			// Allow the page to transform action to a portlet action url
			if (String.IsNullOrEmpty (customAction)) {
				string queryString = req.QueryStringRaw;
				action = CreateActionUrl (VirtualPathUtility.ToAppRelative (req.CurrentExecutionFilePath) +
					(string.IsNullOrEmpty (queryString) ? string.Empty : "?" + queryString));
			}
			else
				action = customAction;

#endif

			XhtmlConformanceSection xhtml = WebConfigurationManager.GetSection ("system.web/xhtmlConformance") as
				XhtmlConformanceSection;
			
			if (xhtml != null && xhtml.Mode == XhtmlConformanceMode.Legacy)
				w.WriteAttribute ("name", Name);

			w.WriteAttribute ("method", Method);
			if (String.IsNullOrEmpty (customAction))
				w.WriteAttribute ("action", action, true);

			/*
			 * This is a hack that guarantees the ID is set properly for HtmlControl to
			 * render it later on. As ugly as it is, we use it here because of the way
			 * the ID, ClientID and UniqueID properties work internally in our Control
			 * code.
			 *
			 * Fixes bug #82596
			 */
			if (ID == null) {
#pragma warning disable 219
				string client = ClientID;
#pragma warning restore 219
			}
			
			string submit = page != null ? page.GetSubmitStatements () : null;
			if (!String.IsNullOrEmpty (submit)) {
				Attributes.Remove ("onsubmit");
				w.WriteAttribute ("onsubmit", submit);
			}
			
			/* enctype and target should not be written if
			 * they are empty
			 */
			string enctype = Enctype;
			if (!String.IsNullOrEmpty (enctype))
				w.WriteAttribute ("enctype", enctype);

			string target = Target;
			if (!String.IsNullOrEmpty (target))
				w.WriteAttribute ("target", target);

			string defaultbutton = DefaultButton;
			if (!String.IsNullOrEmpty (defaultbutton)) {
				Control c = FindControl (defaultbutton);

				if (c == null || !(c is IButtonControl))
					throw new InvalidOperationException(String.Format ("The DefaultButton of '{0}' must be the ID of a control of type IButtonControl.",
											   ID));

				if (page != null && DetermineRenderUplevel ()) {
					w.WriteAttribute (
						"onkeypress",
						"javascript:return " + page.WebFormScriptReference + ".WebForm_FireDefaultButton(event, '" + c.ClientID + "')");
				}
			}

			/* Now remove them from the hash so the base
			 * RenderAttributes can do all the rest
			 */
			Attributes.Remove ("method");
			Attributes.Remove ("enctype");
			Attributes.Remove ("target");

			base.RenderAttributes (w);
		}