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

The Archive Base Latest Questions

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

I need to generate buttons initially based on quite a processor and disk intensive

  • 0

I need to generate buttons initially based on quite a processor and disk intensive search. Each button will represent a selection and trigger a postback. My issue is that the postback does not trigger the command b_Command. I guess because the original buttons have not been re-created. I cannot affort to execute the original search in the postback to re-create the buttons so I would like to generate the required button from the postback info.

How and where shoud I be doing this? Should I be doing it before Page_Load for example? How can I re-construct the CommandEventHandler from the postback – if at all?

   namespace CloudNavigation {     public partial class Test : System.Web.UI.Page     {         protected void Page_Load(object sender, EventArgs e)         {             if (IsPostBack)             {                 // how can I re-generate the button and hook up the event here                 // without executing heavy search 1             }             else             {                 // Execute heavy search 1 to generate buttons                 Button b = new Button();                 b.Text = 'Selection 1';                 b.Command += new CommandEventHandler(b_Command);                 Panel1.Controls.Add(b);             }         }          void b_Command(object sender, CommandEventArgs e)         {             // Execute heavy search 2 to generate new buttons             Button b2 = new Button();             b2.Text = 'Selection 2';             b2.Command += new CommandEventHandler(b_Command);             Panel1.Controls.Add(b2);         }     } } 
  • 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. 2026-05-10T22:23:34+00:00Added an answer on May 10, 2026 at 10:23 pm

    The b_Command Event Handler method is not being executed because on post back buttons are not being recreated (since they are dynamically generated). You need to re-create them every time your page gets recreated but in order to do this you need to explicitly cache information somewhere in state.

    If this a page-scoped operation easiest way is to store it in the ViewState (as strings – if you start loading the ViewState with objects you’ll see performance go down) so that you can check it on next load (or any other previous event) and re-create buttons when reloading the page. If the operation is session-scoped, you can easily store an object (array or whatever) in session and retrieve it on next Load (or Init) to re-create your controls.

    This scenario means that you need just to store some info about your button in your b_Command EventHandler instead of creating and adding buttons since if you do so you’ll lose relative information in the next postback (as it is happening now).

    so your code would become something like:

    namespace CloudNavigation {     public partial class Test : System.Web.UI.Page     {         protected void Page_Load(object sender, EventArgs e)         {             if (IsPostBack)             {                 this.recreateButtons();             }             else             {                 // Execute heavy search 1 to generate buttons                 Button b = new Button();                 b.Text = 'Selection 1';                 b.Command += new CommandEventHandler(b_Command);                 Panel1.Controls.Add(b);                 //store this stuff in ViewState for the very first time             }         }          void b_Command(object sender, CommandEventArgs e)         {             //Execute heavy search 2 to generate new buttons             //TODO: store data into ViewState or Session             //and maybe create some new buttons         }          void recreateButtons()         {             //retrieve data from ViewState or Session and create all the buttons             //wiring them up to eventHandler         }     } } 

    If you don’t want to call recreateButtons on page load you can do it on PreLoad or on Init events, I don’t see a difference since you’ll be able to access ViewState/Session variables everywhere (on Init viewstate is not applied but you can access it to re-create your dynamic buttons).

    Someone will hate this solution but as far as I know the only way to retain state data server-side is ViewState – Session – Page.Transfer or client-side cookies.

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

Sidebar

Ask A Question

Stats

  • Questions 177k
  • Answers 177k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A solution is to write a "before INSERT" trigger which… May 12, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer You say this is a data warehouse. Are you using… May 12, 2026 at 3:26 pm
  • Editorial Team
    Editorial Team added an answer I don't know of a site that catalogs them directly,… May 12, 2026 at 3:26 pm

Related Questions

Question: Is there a way to detect what XHtml conformance setting a particular ASP.Net
I'm building a heavily CRUD based ASP.NET website and I've got to the phase
I am haveing problems getting the command event args following the second click using
I don't think this is technically a macro but I don't know what else

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.