ActionlessForm/ActionlessForm.cs

(完整代码) 1KB

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace ActionlessForm
{
	/// <summary>
	/// The Form class extends the HtmlForm HTML control by overriding its RenderAttributes()
	/// method and NOT emitting an action attribute.
	/// </summary>
	public class Form : System.Web.UI.HtmlControls.HtmlForm
	{
		/// <summary>
		/// The RenderAttributes method adds the attributes to the rendered &lt;form&gt; tag.
		/// We override this method so that the action attribute is not emitted.
		/// </summary>
		protected override void RenderAttributes(HtmlTextWriter writer)
		{
			// write the form's name
			writer.WriteAttribute("name", this.Name);
			base.Attributes.Remove("name");

			// write the form's method
			writer.WriteAttribute("method", this.Method);
			base.Attributes.Remove("method");

			// remove the action attribute
			base.Attributes.Remove("action");

			// finally write all other attributes
			this.Attributes.Render(writer);
			if (base.ID != null)
				writer.WriteAttribute("id", base.ClientID);
		}

	}
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。