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

  • Home
  • SEARCH
  • 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 6041775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:42:36+00:00 2026-05-23T06:42:36+00:00

I generated a few buttons and attached to them an eventhandler like this: Button

  • 0

I generated a few buttons and attached to them an eventhandler like this:

Button pgs = new Button();//Create New Topic
pgs.Width = 20;
pgs.Command += obtainTopicsPerPage_Click;
pgs.CommandName = tPage.ToString();
pgs.Text = tPage.ToString();
btns.Add(tPage.ToString());
buttons.Add(pgs);
}

void obtainTopicsPerPage_Click(Object sender, CommandEventArgs e)
{
    foreach (var item in tPages)
    {
        if (item.Key == e.CommandName)
        {
            foreach (var posts in item.Value)
            {
                posts.ExecuteAll();
             }
        }
    }
    MyButtonTable();
}

Now, the eventhandler never triggers when i click on the button. i check with the debugger,,and when i click the button, there is only a postback,,but it doesnt reach inside the eventhandler functoin

Update:

    void Page_PreInit(object sender, EventArgs e)
{
    List<Button> btn=(List<Button>)ViewState["Buttons"];
    foreach (var item in btn)
    {
            item.Width = 20;
            item.Command += obtainTopicsPerPage_Click; //resigning the eventhandlers from the begining
             item.CommandName = tPage.ToString();
             item.Text = tPage.ToString();
    }
}
  • 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-23T06:42:37+00:00Added an answer on May 23, 2026 at 6:42 am

    This is often the case when dynamically generating the buttons. When the page posts back, the page doesn’t have the buttons any more and therefore can’t bind them to the event handlers.

    The simplest solution is to make sure you re-generate all the buttons in the Page_Init on every load of the page.

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

Sidebar

Related Questions

Inside asp.net form I have few dynamically generated buttons, all of this buttons submit
I'd like to check a few queries generated by ActiveRecord, but I don't need
I am trying to get a graph generated through flot.I have few textboxes like
I've seen a few questions like this around SO but couldn't find anything that's
I have a page with a few fields and a runtime-generated image on it.
I generated drop down menus for my site in Vista Buttons. When it exports
I generated a new form using sean-gen (seam new-form) and added another field to
I have a Windows form that's generated using code (including buttons and what not).
I've generated a new Web Application project using GWT 2.0.4. I replace the onModuleLoad()
I have php generated pages that change every few minutes based on the underlying

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.