Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent handler called only on second click
    text
    copied!<p>I'm building a dynamic button view, which adds buttons programmatically depending on the amount of items in the database. Like a simple workflow engine. On the first page call the event handler works like expected. The new page with the new item is builded and returned to the client. On the second postback the event handler is NOT called and the view keeps the same items. By reclicking the same button (third postback), the breakpoint in the event handler is hitted.</p> <p>My issue is why is the event handler not called even if i'm rebuilding the page (override OnInit()) on each post back?</p> <p>For information: The methods <code>LoadViewWithAlphabeticalDatasource()</code> and <code>LoadViewWithWorkflowItem()</code> does quite the same, so i deleted one in section below. The events are added in same way.</p> <p>Code: </p> <pre><code>&lt;pre&gt; namespace EPS.Web.View.Article { public class DynamicGridView : BasePage, IDynamicGridView { protected override void OnInit(EventArgs e) { Presenter = new DynamicGridPresenter(this); if (IsPostBack) { if (Presenter.Step smallerthan 2) { LoadViewWithAlphabeticalDatasource(); } else { LoadViewWithWorkflowItem(); } } } [PageMethod] protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { SetSubmenuVisible = false; Presenter.InitView(); PrepareView(); } AddEvents(); AddLabels(); PageMethodsEngine.InvokeMethod(this); } private void Back_Clicked(object sender, EventArgs e) { Presenter.StepEngine(DynamicGridPresenter.BACK, string.Empty, string.Empty); PrepareView(); } private void Cancel_Clicked(object sender, EventArgs e) { Presenter.StepEngine(DynamicGridPresenter.CANCEL, string.Empty, string.Empty); PrepareView(); } private void ForwardString(object sender, EventArgs e) { Presenter.StepEngine(DynamicGridPresenter.FORWARD, ((LinkButton)sender).CommandArgument, string.Empty); PrepareView(); } private void ForwardWorkflowItem(object sender, EventArgs e) { Presenter.StepEngine(DynamicGridPresenter.FORWARD, string.Empty, ((LinkButton)sender).CommandArgument); PrepareView(); } protected void PrepareView() { phDynamicGridView.Controls.Clear(); if (Presenter.Step smallerthan 2) { LoadViewWithAlphabeticalDatasource(); } else { LoadViewWithWorkflowItem(); } } private void LoadViewWithWorkflowItem() { var table = new HtmlTable(); table.Attributes.Add("class", "tableDynamicGrid"); int max = GetRowLength(WODatasource.Count); int temp = 1; int actualPosition = 0; int itr = 1; var tr = new HtmlTableRow(); if (WODatasource.Count == 0) { phDynamicGridView.Controls.Add(new HtmlTable()); return; } foreach (WorkflowItem s in WODatasource) { if (actualPosition biggerOrEqual MaxLength &amp;&amp; temp smallerOrEqual max) { table.Rows.Add(tr); actualPosition = 0; temp++; tr = new HtmlTableRow(); } actualPosition++; var cell = new HtmlTableCell(); // cell.Attributes.Add("class", "cellDynamicGrid"); var btn = new LinkButton { CommandArgument = s.Oid.ToString(), Text = s.SelectionItem.Name /*, CssClass = "linkButtonDynamicGrid"*/ }; btn.Click += ForwardWorkflowItem; cell.Controls.Add(btn); tr.Cells.Add(cell); if (itr == WODatasource.Count &amp;&amp; temp smallerOrEqual max) { while (itr biggerOrEqual WODatasource.Count &amp;&amp; itr smallerThan max*MaxLength) { tr.Cells.Add(new HtmlTableCell()); itr++; } table.Rows.Add(tr); phDynamicGridView.Controls.Add(table); return; } itr++; } } } &lt;/pre&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload