Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First of all, I can assure you that your custom HTMLTextWriter is being called correctly, and that you are doing nothing wrong in configuration.</p> <p>Using your web.config section, I wrote a test app, and included the following breakpoint on the <code>var cap = ...</code> line:</p> <pre><code> protected void UpdatePanel1_Load(object sender, EventArgs e) { var cap = Request.Browser.TagWriter; } </code></pre> <p>On both initial HTTP GET and the AJAX postback, the breakpoint is hit, and I could see that the TagWriter being used was in fact CustomHtmlTextWriter. Also, I could set a breakpoint on the CustomHtmlTextWriter constructor, and this breakpoint is hit on postback.</p> <p>I also confirmed that even when you add a brand new control on a postback, even though the CustomHtmlTextWriter constructor is invoked, the OnTagRender, OnAttributeRender, and other events, do not fire.</p> <p>Also, the RenderBefore...() and RenderAfter...() methods are not invoked.</p> <p>So this answers your question "Am I doing anything wrong in my configuration?": No, you are not. Your custom HtmlTextWriter is instantiated and referenced, but none of its useful methods are called (BeginRender is called, but none of the methods you would normally use to alter tags is called).</p> <p>At this point, it is worth noting that the browserCaps tag is deprecated in .NET 2.0, so it is perhaps not surprising that your use case does not seem to be supported. Depending on what exactly you are trying to do, I think the ControlAdapter architecture should get the job done.</p> <p>For example, let's say I want to replace all TextBoxes and Labels with only a span containing their IDs, and have this work on initial GET as well as AJAX postback. Surely your example will be more complicated, but hopefully this simplification will give you the idea.</p> <p>All I need to do is create a ControlAdapter that can act on any web control:</p> <pre><code>public class CustomControlAdapter : WebControlAdapter { protected override void RenderBeginTag(HtmlTextWriter writer) { writer.WriteLine(); writer.WriteBeginTag("span"); writer.Write(HtmlTextWriter.TagRightChar); } protected override void RenderEndTag(HtmlTextWriter writer) { writer.WriteEndTag("/span"); writer.WriteLine(); } protected override void RenderContents(HtmlTextWriter writer) { writer.WriteLine(Control.ID); } } </code></pre> <p>And then, I wire it up to the kinds of controls I'm interested in it working on. I do this by creating a Adapters.browser file in the App_Browsers folder, and including the following configuration:</p> <pre><code>&lt;browsers&gt; &lt;browser refID="Default"&gt; &lt;controlAdapters&gt; &lt;adapter controlType="System.Web.UI.WebControls.Label" adapterType="WebApplication1.CustomControlAdapter" /&gt; &lt;adapter controlType="System.Web.UI.WebControls.TextBox" adapterType="WebApplication1.CustomControlAdapter" /&gt; &lt;/controlAdapters&gt; &lt;/browser&gt; &lt;/browsers&gt; </code></pre> <p>Notice that my browser refID of "Default" will have this work on all browsers. Now when a Label or TextBox web control needs to be rendered, the CustomControlAdapter will take care of it. The above code is tested in my sample app, and works perfectly even with AJAX. In your case, I would guess you just need to add a few more control types to the Adapters.browser file above, and you should be 100% in business.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload