The example looks a bit long. But it is necessary to understand my question.
if (IsPostBack)
{
for (int j = 0; j < PostsDic.Count; j++)//The number is 2. 2 buttons to be created.
{
Button pgs2 = new Button();//Create New Topic
pgs2.Width = 20;
pgs2.Command += obtainTopicsPerPage_Click;
pgs2.EnableViewState = false;
pgs2.CommandName = j.ToString();
pgs2.Text = j.ToString();
buttons.Add(pgs2);
}
if (!FirstList)
{
ListFirstPage();//Creates a few tables and makes it look like a thread table in a forum
FirstList = true;
}
}
Additional information:
FirstLoad is simply a prop:
public bool FirstList { get { return ViewState["first"] == null ? false : (bool)ViewState["first"]; } set { ViewState["first"] = value; } }
ListFirstPage() method looks like this:
void ListFirstPage()
{
//Dictionary<int, List<AllQuestionsPresented>>
foreach (var item in PostsDic)
{
foreach (var apply in PostsDic[item.Key])
{
DisplayAllQuestionsTable objectToList = new DisplayAllQuestionsTable(this, apply.Name, apply.ThreadName, apply.Topic, apply.Subtopic, apply.Views, apply.Replies, apply.PageNumber, apply.Time, PlaceHolder2);
objectToList.ExecuteAll();
}
}
The button event looks like this:
enter code here void obtainTopicsPerPage_Click(Object sender, CommandEventArgs e)
{
//Dictionary<int, List<AllQuestionsPresented>>
foreach (var item in PostsDic)
{
if (item.Key.ToString() == e.CommandName)
{
int ds=0;
foreach (var apply in PostsDic[item.Key])
{
DisplayAllQuestionsTable objectToList = new DisplayAllQuestionsTable(this, apply.Name, apply.ThreadName, apply.Topic, apply.Subtopic, apply.Views, apply.Replies, apply.PageNumber, apply.Time, PlaceHolder2);
objectToList.ExecuteAll();
}
}
}
What happens is this.. When I click a button that i have on the form the ListFirstPage() is triggered, this leads to a list of tables being listed, and a page bar (2 buttons with numbers on them i.e. 1 ,2). When i press button 2 i expect the iteration inside the button event to happen/ But instead, nothing happens the form goes blank and nothing is generated. Why is that? Note that the algorithm in the ListFirstPage and the buttons events is identical!!!!