My issue is the page posts back but does not call the method.
Here is where I create the link Buttons inside the RenderProducts method
for (var counter = 1; counter <= numberOfPages; counter++)
{
var pagingLink = new LinkButton
{
Text = " " + counter.ToString(CultureInfo.InvariantCulture) + " ",
ID = "page" + counter
};
pagingLink.Attributes["runAt"] = "server";
pagingLink.Attributes["class"] = "paging-link";
pagingLink.Attributes.Add("AutoPostBack", "true");
pagingLink.Attributes.Add("AutoEventWireup", "true");
pagingLink.Click +=ChangePage;
paging.Controls.Add(pagingLink);
}
The method it is calling
public void ChangePage(object sender, EventArgs args)
{
// handle this particular case
RenderProducts(2);
}
For completeness below you will see on PostBack I prevent it’s default action
protected void Page_Load(object sender, EventArgs e)
{
GetSideBar();
BuildRefineSearch();
PopulateList();
PerformSearch();
if(!IsPostBack )
{
RenderProducts(1);
}
}
I moved everything to the
override protected void OnInit(EventArgs e)
as this was a user control this solved my issue.
Thanks to Chandermani for getting me to think about when my event was firing.