Take the community feedback survey now.
                AI OnAI Off
            
        Take the community feedback survey now.
        protected override void Render(HtmlTextWriter writer)
        {
            HtmlForm form = Control as HtmlForm;
            if (form == null)
                throw new Exception("HtmlFormAdapter must be used to render a form. Check your .browser file adapter mappings");
            writer.WriteBeginTag("form");
            RenderAttributes(writer);
            writer.Write(HtmlTextWriter.TagRightChar);
            RenderChildren(writer);
            writer.WriteEndTag("form");
        }
        protected void RenderAttributes(HtmlTextWriter writer)
        {
            HtmlForm form = Control as HtmlForm;
            Page page = this.Page;
            if (form == null)
                throw new Exception("HtmlFormAdapter must be used to render a form. Check your .browser file adapter mappings");
            if (page == null)
                throw new Exception("HtmlFormAdapter must be used to render a form that is placed on a Page");
            writer.WriteAttribute("method", form.Method);
            form.Attributes.Remove("method");
            writer.WriteAttribute("action", HttpContext.Current.Request.RawUrl, true);
            form.Attributes.Remove("action");
            if (this.Browser.EcmaScriptVersion.Major > 0)
            {
                //Handle onSubmit scripts
                string clientOnSubmitEvent = "return typeof(WebFormOnSubmit) != 'undefined') ? WebForm_OnSubmit() : true;";
                string onSubmit = form.Attributes["onsubmit"];
                if (!string.IsNullOrEmpty(onSubmit))
                {
                    if (!onSubmit.EndsWith(";"))
                        onSubmit += ";";
                    page.ClientScript.RegisterOnSubmitStatement(typeof(HtmlForm), "OnSubmitScript", onSubmit);
                    form.Attributes.Remove("onsubmit");
                }
                
                writer.WriteAttribute("onsubmit", clientOnSubmitEvent);
                //Handle default button scripts
                if (!string.IsNullOrEmpty(form.DefaultButton))
                {
                    Control button = form.FindControl(form.DefaultButton);
                    if ((button == null) && (this.Page != null))
                    {
                        if (form.DefaultButton.IndexOfAny(new char[] { '$', ':' }) != -1)
                        {
                            button = this.Page.FindControl(form.DefaultButton);
                        }
                    }
                    if (!(button is IButtonControl))
                    {
                        throw new InvalidOperationException("Only controls that implement IButtonControl can be default buttons.");
                    }
                    
                    writer.WriteAttribute("onkeypress", "return WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
                }
            }
            if (form.ID != null)
                writer.WriteAttribute("id", form.ClientID);
            form.Attributes.Render(writer);
        }
                        
        protected void RenderAttributes(HtmlTextWriter writer)
        {
            HtmlForm form = Control as HtmlForm;
            Page page = this.Page;
            if (form == null)
                throw new Exception("HtmlFormAdapter must be used to render a form. Check your .browser file adapter mappings");
            if (page == null)
                throw new Exception("HtmlFormAdapter must be used to render a form that is placed on a Page");
            writer.WriteAttribute("method", form.Method);
            form.Attributes.Remove("method");
            writer.WriteAttribute("action", HttpContext.Current.Request.RawUrl, true);
            form.Attributes.Remove("action");
            if (this.Browser.EcmaScriptVersion.Major > 0)
            {
                //Handle onSubmit scripts
                string clientOnSubmitEvent = "return (typeof(WebForm_OnSubmit) != 'undefined') ? WebForm_OnSubmit() : true;";
                string onSubmit = form.Attributes["onsubmit"];
                if (!string.IsNullOrEmpty(onSubmit))
                {
                    if (!onSubmit.EndsWith(";"))
                        onSubmit += ";";
                    page.ClientScript.RegisterOnSubmitStatement(typeof(HtmlForm), "OnSubmitScript", onSubmit);
                    form.Attributes.Remove("onsubmit");
                }
                
                writer.WriteAttribute("onsubmit", clientOnSubmitEvent);
                //Handle default button scripts
                if (!string.IsNullOrEmpty(form.DefaultButton))
                {
                    Control button = form.FindControl(form.DefaultButton);
                    if ((button == null) && (this.Page != null))
                    {
                        if (form.DefaultButton.IndexOfAny(new char[] { '$', ':' }) != -1)
                        {
                            button = this.Page.FindControl(form.DefaultButton);
                        }
                    }
                    if (!(button is IButtonControl))
                    {
                        throw new InvalidOperationException("Only controls that implement IButtonControl can be default buttons.");
                    }
                    
                    writer.WriteAttribute("onkeypress", "return WebForm_FireDefaultButton(event, '" + button.ClientID + "')");
                }
            }
            if (form.ID != null)
                writer.WriteAttribute("id", form.ClientID);
            form.Attributes.Render(writer);
        }
                        
    
    
    
namespace MyNamespace { public class HtmlFormAdapter : ControlAdapter { protected override void Render(HtmlTextWriter writer) { HtmlForm form = Control as HtmlForm; if (form == null) throw new Exception("HtmlFormAdapter must be used to render a form. Check your .browser file adapter mappings"); writer.WriteBeginTag("form"); writer.WriteAttribute("name", form.Name); writer.WriteAttribute("method", form.Method); foreach (string key in form.Attributes.Keys) writer.WriteAttribute(key, form.Attributes[key]); writer.WriteAttribute("action", HttpContext.Current.Request.RawUrl); if (form.ID != null) writer.WriteAttribute("id", form.ClientID); writer.Write(HtmlTextWriter.TagRightChar); RenderChildren(writer); writer.WriteEndTag("form"); } } }and in your ~/App_Browsers/AdapterMappings.browser file