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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:58:49+00:00 2026-06-15T07:58:49+00:00

I am new to custom controls in asp.net. I am facing difficulty while attaching

  • 0

I am new to custom controls in asp.net. I am facing difficulty while attaching the click event handler for the image button. I written the following code for server control.

        ImageButton _imgbtn;
        TextBox txtOutput;
        Label _lblname;
        public ImageButton searchBtn
        {
            get { return _imgbtn; }
            set { _imgbtn = value; }
        }

        public Label lblName
        {
            get { return _lblname; }
            set { _lblname = value; }
        }
        protected override void OnInit(EventArgs e)
        {
             txtOutput = new TextBox();
            txtOutput.Width = 180;
            txtOutput.ID = "ResultOutput";
            txtOutput.Enabled = false;
            Controls.Add(txtOutput);

            searchBtn = new ImageButton();
            Controls.Add(searchBtn);
            lblName = new Label();
            lblName.Text = "";
            Controls.Add(lblName);

        }
        protected override void RenderContents(HtmlTextWriter output)
        {
            //base.Render(output);
            txtOutput.RenderControl(output);
            searchBtn.RenderControl(output);
            lblName.RenderControl(output);
        }

I added this custom control to the .aspx page with register tag as follows.

<%@ Register TagPrefix="mycontrol" Namespace="MyControl" Assembly="MyControl" %> 

In aspx.cs file I give the property values as below,

        CustomControl mycustctrol;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                mycustctrol = myCust as CustomControl;
                mycustctrol.searchBtn.ImageUrl = "~/Images/searchicon.png";
                mycustctrol.searchBtn.OnClientClick = "GenerateClickEvent"

            }
        }


public void GenerateClickEvent(object sender, EventArgs args)
    {
        mycustctrol.lblName.Text = "clicked";
    }

After running this application I am getting the following error.

‘GenerateClickEvent’ is undefined

Where I done the mistake. I tried with declaring an event like public event EventHandler GenerateClickEvent;, but I am unable to go further. Can you please show me the way how to achieve this.

I also tried with the javascript function in the .aspx page as

function GenerateClickEvent() {

        alert('clicked');
    }

alert('clicked'); is not firing.

  • 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-06-15T07:58:50+00:00Added an answer on June 15, 2026 at 7:58 am

    you probably want something like this what you are doing is for client click

     mycustctrol.searchBtn.OnClientClick = "GenerateClickEvent()"
    

    and something like this for the event click

     mycustctrol.searchBtn.Click += new ImageClickEventHandler(GenerateClickEvent_Click);
    
     protected void GenerateClickEvent_Click(object sender, ImageClickEventArgs e) 
      {
            mycustctrol.lblName.Text = "clicked";
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to writing custom ASP.NET server controls, and I'm encountering the following issue:
we are currently developing a couple of custom asp.net server controls. Now we'd like
There are a lot of ways to build custom controls for Asp.Net. Some people
I have a custom ASP.NET control. In its Init handler I add a delegate
I'm new to working in ASP.NET but I'm developing a custom control that has
New developer here,Im using the Custom Image Picker by ray wenderlich. But what I
I'm new to ASP.net, the ViewState, and C# in general. I have some code
I have a custom ASP.NET user control that is added to a panel on
I have an issue in asp.net 4. When I add an attribute on controls,
I am new to the asp.net world (but not new to .net) and I

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.