locked
CSS Friendly conflicts with AJAX? RRS feed

  • Question

  • User1465073448 posted

    I'm using CSS Friendly to override the Render() function in order to make the postback url (the action attribute of the form) the rewritten url, it works fine until i decide to use AJAX in my application. I always get a "Object reference not set to an instance of an object." exception every time a ajax request is made. I believe it's the "((System.Web.UI.PageRequestManager.ParserHtmlTextWriter)(writer)).FormAction" that is null, but I was unable to access to it because of some "protected level" ?!!?? Here's the code:

      

    <browsers>
      <browser refID="Default">
        <controlAdapters>
          <adapter controlType="System.Web.UI.HtmlControls.HtmlForm"
                   adapterType="FormFixControlAdapter" />
        </controlAdapters>
      </browser>
    </browsers>
      
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    /// <summary>
    /// Summary description for FormFixHtmlTextWriter
    /// </summary>
    public class FormFixHtmlTextWriter : HtmlTextWriter
    {
    	public FormFixHtmlTextWriter(HtmlTextWriter writer) : base(writer)
    	{
                this.InnerWriter = writer;
    	}
    
        public override void WriteAttribute(string name, string value, bool fEncode) {
            //if the attribute we are writing is "action" attribute then
            //replace the value with the VirtualUrl
    
            if (string.Compare(name, "action", true) == 0) {
                value = HttpContext.Current.Request.RawUrl;            
            }
    
            base.WriteAttribute(name, value, fEncode);
        }
    
    }
    
    
    public class FormFixControlAdapter : System.Web.UI.Adapters.ControlAdapter {
        protected override void Render(HtmlTextWriter writer) {    
            
            base.Render(new FormFixHtmlTextWriter(writer)); //exception occured on this line
            
        }
    }
     
    Monday, September 10, 2007 11:00 AM

Answers

  • User1494513751 posted

    The problem is that you need to set this.InnerWriter to writer.InnerWriter in your FormFixHtmlTextWriter constructor. Not sure why, but I had the same problem until I did this. Here's a snippet of my code, where I made this change to fix the AJAX/Atlas issue.

    public class RewriteFormHtmlTextWriter : HtmlTextWriter
    {
        public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
        {
            // MUST USE .InnerWriter, lest ATLAS breaks
            this.InnerWriter = writer.InnerWriter;
        }

        public RewriteFormHtmlTextWriter(System.IO.TextWriter writer) : base(writer)
        {
            this.InnerWriter = writer;
        }

     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2007 3:29 PM

All replies

  • User1494513751 posted

    The problem is that you need to set this.InnerWriter to writer.InnerWriter in your FormFixHtmlTextWriter constructor. Not sure why, but I had the same problem until I did this. Here's a snippet of my code, where I made this change to fix the AJAX/Atlas issue.

    public class RewriteFormHtmlTextWriter : HtmlTextWriter
    {
        public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
        {
            // MUST USE .InnerWriter, lest ATLAS breaks
            this.InnerWriter = writer.InnerWriter;
        }

        public RewriteFormHtmlTextWriter(System.IO.TextWriter writer) : base(writer)
        {
            this.InnerWriter = writer;
        }

     
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 10, 2007 3:29 PM
  • User1465073448 posted

    thank you very much for you help. you made my day!

    Monday, September 10, 2007 4:58 PM