Click here to Skip to main content
16,019,976 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have paging user control.

pager.ascx code
C#
public delegate void PageChangedEventHandler(object sender, CustomPageChangeArgs e);
public event PageChangedEventHandler PageChanged;
protected void lnkPageNumbers_Click(object sender, EventArgs e)
{
    SetCurrentPage(Convert.ToInt32(((LinkButton)sender).Text));
}
private void SetCurrentPage(int currentPage)
{
    Pager_PageChanged(this, args);
    //Some code
}


If I add user control at compile time it works

XML
<Custom:Pager ID="CustomPager"  runat="server"  önPageChanged="CustomPager_PageChanged" />;


********
If user control added at runtime it work partially. I am able to set properties of user control but I am not able to fire event on page number click.

parent.aspx code
C#
if (some condition)
{
 LinkPager CustomPager1 = (LinkPager)LoadControl("~/LinkPager.ascx"); 
 CustomPager1.PageChanged+=new LinkPager.PageChangedEventHandler(this.CustomPager_PageChanged);  
}
protected void CustomPager_PageChanged(object sender, CustomPageChangeArgs e)
{
    //some code
}


I am not getting any error but CustomPager_PageChanged is not getting called.

Please let me know if anybody has any idea about the issue.

Thanks,
Nagraj
Posted
Updated 9-May-11 19:28pm
v2

1 solution

The "some condition" should be in page load or upper events and it must be true when page is posted back on click of element in user control.

Check your markup where you've added the event handler, it doesn't have any condition to attach the event handler that means the event handler is attached to the event every time.

Thanks,
Hemant
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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