The b_Command event handler method is not executed because the post back buttons are not recreated (because they are dynamically generated). You need to recreate them every time your page is recreated, but for this you need to explicitly cache the information somewhere in the state.
If this makes it easier to work with the page area, save it to the ViewState (in the form of strings - if you start loading the ViewState with objects, you will see that the performance decreases), so you can check it at the next load (or any other previous event) and re-create buttons when reloading the page. If the operation is limited to the session, you can easily save the object (array or something else) in the session and get it the next time you load (or initialize) to recreate the controls.
This scenario means that you just need to save some information about your button in your b_Command EventHandler, rather than creating and adding buttons, because if you do this, you will lose relative information in the next postback (as it is now).
so your code will 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 {
If you do not want to call recreateButtons on page loading, you can do it on PreLoad or on Init events, I donβt see a difference, since you can access ViewState / Session variables all over the world (in the Init window, the viewstate is not applied, but you can access it to recreate the dynamic buttons).
Someone will hate this decision, but as far as I know, the only way to save the state database is ViewState - Session - Page. Pass or client side cookies.
JohnIdol
source share