Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6167671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:33:11+00:00 2026-05-23T22:33:11+00:00

I have a custom ASP.NET button with an image element inside it (and an

  • 0

I have a custom ASP.NET button with an image element inside it (and an asp literal). I want a button with an image an text, but I would prefer not to use CSS as setting the background image with CSS seems to remove all of the standard button formatting (gradients, borders, etc, that are automatically created). I have the button hooked up to a standard server-side click event. I have the button placed inside an ASP:UpdatePanel. When I open the site in Chrome (v 12) and click directly on the image rendered on the button, the click event on the server-side doesn’t fire. There is a post-back though. If I use FireFox or IE, it works fine (ie, the server-side ConfirmButton_Click fires). And if I have the button outside of the UpdatePanel, it is also fine in Chrome.

Code (I left out the imports):

1.My custom button that allows an Image:

namespace MyControlLibrary
{
/// <summary>
/// Render an HTML button instead of an input element.
/// </summary>
[ToolboxData("<{0}:HTMLButton runat=server></{0}:HTMLButton>")]
[ParseChildren(false)]
[PersistChildren(true)]
public class HTMLButton : Button
{
    protected override HtmlTextWriterTag TagKey
    {
        get
        {
            return HtmlTextWriterTag.Button;
        }
    }

    protected override void RenderContents(HtmlTextWriter output)
    {

        RenderChildren(output);
    }
}
}

2.The page, code-behind:

 namespace WebApplication2
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void ConfirmButton_Click(object sender, EventArgs e)
            {
                 // would be nice to be able to do something here
            }
       }
    }

3.The ASP Markup:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master"     AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<%@ Register Assembly="MyControlLibrary" Namespace="MyControlLibrary" TagPrefix="CUSTOM" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Always">
        <ContentTemplate>
            <CUSTOM:HTMLButton runat="server" ID="HTMLButton2"     OnClick="ConfirmButton_Click"
                Enabled="true">
                <img id="Img1" runat="server" src="~/images/page_go.png" alt="some alt     text" />
                <asp:Literal ID="Literal1" runat="server" Text="Inside an ASP:UpdatePanel"     />
            </CUSTOM:HTMLButton>
        </ContentTemplate>
    </asp:UpdatePanel>
    <CUSTOM:HTMLButton runat="server" ID="HTMLButton1" OnClick="ConfirmButton_Click"
        Enabled="true">
        <img id="Img2" runat="server" src="~/images/page_go.png" alt="some alt text" />
        <asp:Literal ID="Literal2" runat="server" Text="Just on the page" />
    </CUSTOM:HTMLButton>
</asp:Content>

Update: Additional Information

On the Network tab of the Chrome built-in debugger, I see that when I click directly on the image on the button (thus causing the problem), the Form Data is a little different than when I click on the non-image area of the button.

ScriptManager1:UpdatePanel1|HTMLButton2
__EVENTTARGET:
__EVENTARGUMENT:
__VIEWSTATE:/wEPDwUJNDk5NDQ3MTUyZGSFDQs1Xrosg9lxmcJ 3Q6Nz2 zbrq0CLJEKUy3yWQ0yw==
__EVENTVALIDATION:/wEWAwK8nZ3eAgKqrv38BgLZ8qO9CG7K1tlR9ucFA1AbifYgZtWmVKs/NshLxmxCD39QxIE9
__ASYNCPOST:true
HTMLButton2: 

Above is what I see when I click, not on the image. Ie, it causes the server-side click event to fire as I expect. When I click directly on the image, the “HTMLButton2” is missing from the ScriptManager1 and from the last line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:33:13+00:00Added an answer on May 23, 2026 at 10:33 pm

    Okay, the solution that I found was this: I added a client-side JS/jQuery function tied to onclick of the Img inside the button. It cancels the current event, and does a click on the parent element. Here is the code:

        function clickParent(e) {
            var parentButton = $(e.srcElement).parent().get(0);
            e.preventDefault();
            $(parentButton).click();
        }
    

    As a matter of fact, I actually register this script as well as hook up the onclick of the image from within my custom HTMLButton control so that I don’t have to put the script in every page that uses the button. I didn’t see the need to post those details though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a custom ASP.NET webcontrol and would like it to have a collection
Can you have custom client-side javascript Validation for standard ASP.NET Web Form Validators? For
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible
I have a custom view engine in ASP.NET MVC and since upgrading to RC1
I have a custom memebership provider that has served us well for asp.net web
I have created a simple Asp.Net custom control which automatically combines all the correct
I have an ASP.NET application that uses a custom .NET library (a .DLL file).
i have an ASP.NET web service that returning a custom entity object (Staff): [WebMethod]
I have an ASP.NET project which has already some custom fields in it's web.config
I have a ASP.Net 2.0 website that is currently using a custom MembershipProvider and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.