Change HtmlForm action in C# ASP.NET 3.5

后端 未结 6 1351
醉酒成梦
醉酒成梦 2021-01-18 15:11

I have a form as

When accessing in C# code-behind via



        
6条回答
  •  北恋
    北恋 (楼主)
    2021-01-18 16:04

    You can use the Control Adapters of asp.net.

    Here is a working example:

    public class RewriteFormHtmlTextWriter : HtmlTextWriter
    {
        public RewriteFormHtmlTextWriter(HtmlTextWriter writer)
            : base(writer)
        {
            this.InnerWriter = writer.InnerWriter;
        }
        public RewriteFormHtmlTextWriter(System.IO.TextWriter writer)
            : base(writer)
        {
            base.InnerWriter = writer;
        }
    
        public override void WriteAttribute(string name, string value, bool fEncode)
        {
            if (name == "action")
            {
                value = "Change here your value"            
            }
    
            base.WriteAttribute(name, value, fEncode);
        }
    }
    

    With the above code, and a declare on the App_Browsers with a file called Form.browser

    
      
        
          
        
      
    
    

    you can change the form. Of course this code called in every form render.

    Relative : http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx

提交回复
热议问题