已答复 LinkButton click event in GridView PagerTemplate will not fire

  • 10 Nopember 2009 10:35
     
     
    I have a fairly simple GridView control with two LinkButtons in the GridView's PagerTemplate. The two linkbuttons each have their own OnClick event and if I omit the event handler in the .cs-fil I get an error saying that my UserControl does not implement those two events. So far so good, but if I implement the event handlers, they won't fire. It looks like the page just makes a postback without running through the events. Other events on the same UserControl fires without issues.

    I've already constructed this setup outside SharePoint (i.e. in a simple WebApplication project) and it works fine. The only difference is that in SharePoint I load my UserControl in a WebPart and renders it when I render my WebPart. I've tried hooking up the two events dynamically instead but it didn't help. When I debug the UserControl, all other breakpoints can be reached except those in my event handlers.

    My guess is that at some point the event hookup is lost but I can't figure out how or where this happens since I'm hooking up the event directly in my .ascx file. Is there a way to get a deeper look into events firering than simply putting a breakpoint there?
    • Dipindahkan oleh Mike Walsh FIN 10 Nopember 2009 11:36 programming not general (From:SharePoint - General Question and Answers and Discussion)
    •  

Semua Balasan

  • 10 Nopember 2009 15:55
     
     
    It is hard to be certain without seeing your code. I would suggest that you wire up the events (hook them up dynamically) in the CreateChildControls override after the user control is loaded.
  • 10 Nopember 2009 16:05
     
     
    Hi,

    Try loading your usercontrol during OnInit of your web part. I always like to have controls that handle post back events created early in the page lifecycle.

    Paul.
    • Ditandai sebagai Jawaban oleh Chengyi Wu 12 Nopember 2009 0:54
    • Tanda sebagai Jawaban dihapus oleh Chengyi Wu 12 Nopember 2009 0:54
    •  
  • 11 Nopember 2009 9:02
     
     Jawab
    Okay, I found the cause of this problem. It turns out that setting the GridView.PageSize property OnRender in the UserControl is a bad idea :-)

    I changed my WebPart so that the property is set in CreateChildControls and changed my UserControl so that it uses the property on Page_Load. Now it works like a charm.

    Thanks for all your input!
    • Ditandai sebagai Jawaban oleh Chengyi Wu 12 Nopember 2009 0:54
    •  
  • 11 Juli 2012 13:05
     
     

    Hi,

    Can you please share your piece of work, am also facing the same problem the events which are in my user control are not firing when i have added it in the webpart.