tags:

views:

63

answers:

1

Hi,

I've got an ASP.Net button control that I have overridden to provide different functionality. the code looks as follows.. I'm overriding the Render method to surround the control with an <a>...

    /// <summary>
    /// Render Method
    /// </summary>
    /// <param name="writer"></param>
    protected override void Render(HtmlTextWriter writer)
    {
        base.CssClass = "euva-button-decorated";
        writer.Write("<a class=\"euva-button\">");
        base.Render(writer);
        writer.Write("</a>");
    } 

When I check the generated source on the page, I find that where ASP.Net has injected its click handler it does the following...

 <a class="euva-button"><input type="submit" name="TestButton" value="Test Button" onclick="clickOnce(this);WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;TestButton&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="TestButton" class="euva-button-decorated" /></a>

... it seems to be escaping the output for the double quotes which means that the browser cannot understand the javascript.

How do I make the render method not escape the injected ASP.Net client click handler ??

Note I also have my own client click handler which is declared declaratively in the page mark-up.

A: 

weird. I've done something similar to you and it always works fine. Try this:

public override void RenderControl(HtmlTextWriter writer)
{
    CssClass = "euva-button-decorated";
    //give the 'a' a class
    writer.AddAttribute(HtmlTextWriterAttribute.Class, "euva-button");
    //open 'a'
    writer.RenderBeginTag(HtmlTextWriterTag.A);
    //render the button
    base.RenderControl(writer);
    //close a
    writer.RenderEndTag();
}
BritishDeveloper
I ironically got a "An unhandled exception of type 'System.StackOverflowException' occurred in.." when it attempted to render the begin tag of "A" :).... the call to RenderControl actually caused a re-entry to the overridden Render method. I tried changing base.RenderControl to base.Render but that still didnt work. Thanks though :)
RemotecUk
oh sorry. this should replace the overridden render method.
BritishDeveloper
Hi, just tried that - same effect. Very strange.
RemotecUk
What is it actually doing wrong? I had a look at my source code at it too is escaping all the apostrophes. Still works fine though
BritishDeveloper
I've checked this against the mark up created by standard ASP.Net buttons and they generate the same.
RemotecUk
So what is the problem? What isn't working?
BritishDeveloper