See more:
(untagged)
Dear All,
I have a page holding data in data list. I created paging option for datalist with dynamic link buttons created during-page pre init event. It runs if(!Ispostback).
Then I hold number of pages in session in order not to connect to database in each page refresh.
Then I have dropdown list accorging to which the number of pages changes. So the number of link buttons also should change with selection.
However when I clicked on the button page-preinit creates the link buttons before the it handles click event, therefore creates the link buttons according to the number hold in session, in other words according to previous page number..
Here are the codes
protected void page_Preinit(object sender, EventArgs e)
{
if (!IsPostBack)
{
getpagecount("0","0","0"); // gets the page count form database.
}
else { lb_Count = int.Parse(Session["Page"].ToString()); } //gets the figure in the session.
for (int i = 1; i <= lb_Count; i++)
{
LinkButton bottomLink = new LinkButton();
LiteralControl bottomLiteral = new LiteralControl(" ");
bottomLink.Text = i.ToString();
pnlBottom.Controls.Add(bottomLink);
pnlBottom.Controls.Add(bottomLiteral);
bottomLink.Click += new EventHandler(this.changeLink);
}
if (con!=null && con.State == ConnectionState.Open)
{
con.Close();
cmd.Dispose();
}
}
HERE IS THE CLICKED EVENT
protected void btnYemekler_Click(object sender, ImageClickEventArgs e)
{
//HERE, THE PAGE NUMBER IN SESSION CHANGES BUT THE LINK BUTTOS ARE ALREADY CREATED.
getpagecount(DlAscilar.SelectedValue.ToString(),
DlMutfaklar.SelectedValue.ToString(), DlBolgeler.SelectedValue.ToString());
doldur(DlAscilar.SelectedValue.ToString(),
DlMutfaklar.SelectedValue.ToString(), DlBolgeler.SelectedValue.ToString());
dlListe_Doldur(0);
}
WHAT CAN I DO TO HANDLE THIS PROBLEM.
THANKS IN ADVANCE