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 6895601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:55:47+00:00 2026-05-27T06:55:47+00:00

So I want to add some javascript to the onclick event of several controls

  • 0

So I want to add some javascript to the onclick event of several controls in my web site. They are all of the Button, LinkButton, and ImageButton class.

I’ve created a class called CustomLinkButton that inherits from LinkButton and works perfectly. It makes use of the OnLoad method and has some properties that use ViewState. Great. Now I’d like to use that code for Button and ImageButton.

Problem is, all three of those classes inherit from System.Web.UI.WebControls.WebControl, which is missing some important methods and properties common to all three of these controls.

So what to do? Duplicating code in all the classes means poor maintainability. I’ve tried making another class and writing the methods there but I run into the same problem – I can’t have a method that accepts all three types but I can’t write a generic method with more than one constraint.

Ideas? Or do I just need to write three classes with duplicate code? I’ve done a good deal of searching and can’t find a solution. This could apply to a lot of situations, hence my asking. Thanks guys.

EDIT: Examples of relevant properties they share are CausesValidation and ValidationGroup.

  • 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-27T06:55:48+00:00Added an answer on May 27, 2026 at 6:55 am

    Although they share similar functionality and needs they are indeed different controls for different purposes. I recommend you keep them separate. With enough time, energy and testing you could have one control that renders anything, but is that really what you want?

    You would think LinkButton and ImageButton should inherit from Button, but that is just semantics. You should think about them in terms of what they render, which is HTML:

    • asp:button is a <input type="button">
    • asp:linkbutton is a <a>
    • asp:imagebutton is a <input type="image">
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want to add some client side (JQuery Javascript) validation in a web
I want to add some style to head tag in html page using javascript.
I have some JavaScript code and a button which already has an event/action assigned
One of my clients is asking if they can add some JavaScript to track
Hi all Currently I have a website that has a button and some javascript
I have a website built with ASP.NET (3.5) and want add some level of
I want to add some more library and helpers file into Pyrocms which is
I want to add some no. of days to get the future date. And
I want to add some jQuery functionality to our sites where one piece of
I want to add some html in an email. I've tried the following. vFromName

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.