Click here to Skip to main content
16,021,765 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
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("&nbsp;");
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
Posted

1 solution

My answer may/may not be dirty, but that would work.

1. Place a Server-Side HiddenField in the *.aspx file.
2. Handle the OnClientClick event (JavaScript) of the Button.
3. OnClientClick you have to set the page number or whatever data you want into the HiddenField.
4. After the OnClientClick event, Button's Click process will start.
5. Now in your Page_PreInit get the values of the HiddenField and continue your routine process.
6. Here you can get rid of Session object.

Let me know if you have questions. Please mark it as answer if it helps you.

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900