創建此類并對其進行編譯之后,要在 ASP.NET Web 應用程序中使用它,應首先將其添加到 Web 應用程序的 References 文件夾中。然后,要 使用它來代替 HtmlForm 類,做法是在 ASP.NET 網頁的頂部添加以下內容:


namespace?ActionlessForm
?{
?????public?class?Form?:?System.Web.UI.HtmlControls.HtmlForm
?????{
?????????protected?override?void?RenderAttributes(HtmlTextWriter?writer)
?????????{
?????????????writer.WriteAttribute("name",?this.Name);
?????????????base.Attributes.Remove("name");
?????????????writer.WriteAttribute("method",?this.Method);
?????????????base.Attributes.Remove("method");
?????????????this.Attributes.Render(writer);
?????????????base.Attributes.Remove("action");
?????????????if?(base.ID?!=?null)
?????????????????writer.WriteAttribute("id",?base.ClientID);
?????????}
?????}
?}
?{
?????public?class?Form?:?System.Web.UI.HtmlControls.HtmlForm
?????{
?????????protected?override?void?RenderAttributes(HtmlTextWriter?writer)
?????????{
?????????????writer.WriteAttribute("name",?this.Name);
?????????????base.Attributes.Remove("name");
?????????????writer.WriteAttribute("method",?this.Method);
?????????????base.Attributes.Remove("method");
?????????????this.Attributes.Render(writer);
?????????????base.Attributes.Remove("action");
?????????????if?(base.ID?!=?null)
?????????????????writer.WriteAttribute("id",?base.ClientID);
?????????}
?????}
?}
<%@?Register?TagPrefix="skm"?Namespace="ActionlessForm"?Assembly="ActionlessForm"?%>?
?
?<form?runat="server"></form>
?//替換為:?
?<skm:Form?id="Form1"?method="post"?runat="server"></skm:Form>?
?
?<form?runat="server"></form>
?//替換為:?
?<skm:Form?id="Form1"?method="post"?runat="server"></skm:Form>?