Can I delete the attribute NAME from the FORM tag?

Last post 10-26-2009 10:56 AM by Jorgitto. 3 replies.

Sort Posts:

  • Can I delete the attribute NAME from the FORM tag?

    08-29-2007, 11:12 PM
    • Member
      92 point Member
    • gporras
    • Member since 02-24-2006, 8:43 PM
    • Colombia
    • Posts 102

    Hello...

    I have a APSX page with a form. My page validate with XHTML 1.1.

    The form tag is:

         <form id="Contact" method="post" runat="server"> 

     When I see the page in the browser this form tag is:

        <form name="aspnetForm" method="post" action="default.aspx" id="aspnetForm">

     The .Net 2.0 added the attribute name.

    When I validate my page with the HTML Validator (http://validator.w3.) I get this error:

         This page is not Valid XHTML 1.1!

          Line 80, Column 16: there is no attribute "name": <form name="aspnetForm" method="post"..

     

     How I delete this NAME attrbiute that is added by .Net?

     Thanks! 

  • Re: Can I delete the attribute NAME from the FORM tag?

    08-29-2007, 11:32 PM
    Answer
    • Member
      350 point Member
    • StevenPaul
    • Member since 08-13-2007, 5:31 PM
    • UK
    • Posts 73

    Yes, but you don't delete the attribute, instead create a new HtmlForm class, override RenderAttributes and use the output writer to 'write in' the attributes you need - omitting the name attribute.

    You will need to register the form control within the page your intending to use.

    Be warned: The client JavaScript natively rendered will be affected by this change as it uses the name attribute for PostBack and CallBack events.

    My advice would be to use Transitional rather than Strict.

    You can also use a ControlAdapter, but this again creates the same problems if your going to rely on native ASP.NET behaviour

  • Re: Can I delete the attribute NAME from the FORM tag?

    08-29-2007, 11:38 PM
    Answer
    • Member
      350 point Member
    • StevenPaul
    • Member since 08-13-2007, 5:31 PM
    • UK
    • Posts 73

    Insert the tag prefix for the control below the Page declaration

     <% @ Register TagPrefix="MyTagPrefix" Namespace="MyAssemblyNamespace" Assembly="MyAssembly" %>

    <MyTagPrefix:CustomForm id="aspnetForm" runat="server"></MyTagPrefix:CustomForm

        public class CustomForm : HtmlForm
        {
            protected override void RenderAttributes(HtmlTextWriter output)
            {
                output.WriteAttribute("id", this.ID);
                output.WriteAttribute("method", this.Method);
                output.WriteAttribute("action", HttpContext.Current.Request.Path);
                output.WriteAttribute("runat", "server");
            }
            protected override System.Collections.IDictionary GetDesignModeState()
            {
                
                return base.GetDesignModeState();
            }
        }
     

  • Re: Can I delete the attribute NAME from the FORM tag?

    10-26-2009, 10:56 AM
    • Member
      47 point Member
    • Jorgitto
    • Member since 04-25-2006, 11:22 AM
    • Posts 10

     Add <xhtmlConformance mode="Strict" /> under the <system.web> in the web.config

Page 1 of 1 (4 items)