I create a dynamic button view that programmatically adds buttons based on the number of items in the database. As a simple workflow mechanism. On the first page, an event handler call works as expected. A new page with a new element is created and returned to the client. On the second reverse side, the event handler is NOT called, and the same elements are stored in the view. Using the same button (third postback) removes the breakpoint in the event handler.
My problem is why the event handler is not being called even if I rearrange the page (overrides OnInit ()) backward for each post?
Information: Methods LoadViewWithAlphabeticalDatasource()and LoadViewWithWorkflowItem()do the same thing, so I removed one of them in the section below. Events are added in the same way.
Code:
<pre>
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 && temp smallerOrEqual max)
{
table.Rows.Add(tr);
actualPosition = 0;
temp++;
tr = new HtmlTableRow();
}
actualPosition++;
var cell = new HtmlTableCell();
var btn = new LinkButton
{
CommandArgument = s.Oid.ToString(),
Text = s.SelectionItem.Name
};
btn.Click += ForwardWorkflowItem;
cell.Controls.Add(btn);
tr.Cells.Add(cell);
if (itr == WODatasource.Count && temp smallerOrEqual max)
{
while (itr biggerOrEqual WODatasource.Count && itr smallerThan max*MaxLength)
{
tr.Cells.Add(new HtmlTableCell());
itr++;
}
table.Rows.Add(tr);
phDynamicGridView.Controls.Add(table);
return;
}
itr++;
}
}
}
</pre>
source
share