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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:29:27+00:00 2026-06-09T13:29:27+00:00

Currently, I am doing a project for students’ hostel and now I have to

  • 0

Currently, I am doing a project for students’ hostel and now I have to implement some search strategies about students.Here I have to create a button dynamically when the user clicks on the another server button in .aspx page and accordingly I have to create the onclick event handler for the newly created button. The code-snippet that I used is:

protected void btnsearchByName_Click(object sender, EventArgs e)
    {
        TextBox tbsearchByName = new TextBox();
        Button btnsearchName = new Button();
        tbsearchByName.Width = 250;
        tbsearchByName.ID = "tbsearchByName";
        tbsearchByName.Text = "Enter the full name of a student";
        btnsearchName.ID = "btnsearchName";
        btnsearchName.Text = "Search";
        btnsearchName.Click += new EventHandler(this.btnsearchName_Click);

        pnlsearchStudents.Controls.Add(tbsearchByName);
        pnlsearchStudents.Controls.Add(btnsearchName);
    }
     protected void btnsearchName_Click(object sender, EventArgs e)
    {
        lblsearch.Text = "btnsearchName_Click event fired in " + DateTime.Now.ToString();

    }

Here, the problem is newly created eventHandler doesnot get fired. I have gone through this site and looked several questions and answers and also gone through the page life-cycle and they all say that the dynamic button should be on Init or Pre_init, but my problem is I have to create it when another button is clicked, how can it be possible?

  • 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-09T13:29:29+00:00Added an answer on June 9, 2026 at 1:29 pm

    You need to add the click handler for the button on every postback.

    you could look for the button in the search students panel on page load or try the page OnInit() method to add the handler when its created.

    Also check here:

    Dynamically added ASP.NET button click handler being ignored

    and here:
    asp.net dynamically button with event handler

    and here:
    asp:Button Click event not being fired

    (all of which give similar suggestions)

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

Sidebar

Related Questions

I'm currently doing some research about my project, a smartphone tracking native application, and
I am currently doing a project in which I have to request data from
I'm currently doing a project where I have to interact with a circuit I
I have this interesting obstacle on my project. I am currently doing a MVC3
i'm currently doing a project related to AWS and at some point will need
I am currently doing an mvc3 razor project and I need some charts. I
Currently am doing project on Family Business. In that I need some video calling
I'm currently doing a steganography project (for myself). I have done a bit of
Hi i am currently doing a school project using cakePHP. I have the following
I am currently doing some Project Euler problems and the earlier ones often involve

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.