This is a migrated thread and some comments may be shown as answers.

Attach client side events to Page Numbers in NumericPager

3 Answers 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Satyaprakash J
Top achievements
Rank 1
Satyaprakash J asked on 13 Nov 2009, 04:44 AM
Hi,
  I have a RadGrid with PagerStyle set to GridPagerMode.NumericPager. I would like to attach client side event to the Page Numbers displayed in the Pager. I would like to do something like control.Attributes.Add("onclick", "PageIndexChanging"). How can this be done programmatically

Thanks
Satyaprakash J

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 13 Nov 2009, 06:20 AM
Hello Satyaprakash,

You can simply invoke the onCommand client event on clicking the pager buttons ratehr than adding attributes for each control as shown below:
aspx:
<ClientSettings > 
   <ClientEvents OnCommand="RaiseCommand"/> 
</ClientSettings> 

js:
function RaiseCommand(sender, args) 
    { 
        if(args.get_commandName() == "Page"
        { 
          alert("Page Changed"); 
        }       
    } 

Eventhough, here's the code to add addributes to the pager controls, as well:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridPagerItem) 
        { 
            GridPagerItem pager = (GridPagerItem)e.Item; 
            Panel panel = (Panel)pager.FindControl("ctl01"); 
            foreach (Control ctrl in panel.Controls) 
            { 
                (ctrl as LinkButton).Attributes.Add("onclick""PageIndexChanging();"); 
            } 
        }  
    } 

js:
function PageIndexChanging() 
    { 
       alert("page changed"); 
    } 

Thanks
Princy.
0
Satyaprakash J
Top achievements
Rank 1
answered on 13 Nov 2009, 12:10 PM
Hi,
    I tried the OnCommand Event and it works when a Page Number is clicked. But the OnCommand Event is not raised when we click on the NextPageButton, PrevPageButton, FirstPageButton, LastPageButton. How do we detect the click on these buttons.

Thanks
Satyaprakash J



 
0
Princy
Top achievements
Rank 1
answered on 16 Nov 2009, 08:21 AM
Hello Satyaprakash,

I tried the same scenario at my end and the OnCommand did fire on clicking all the pager buttons. I am not sure as to what could be wrong at your end, but probably you could try the second option I have provided above, which is to add the onclick attribute for every pager button control in the ItemDataBound event of the grid.
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridPagerItem) 
        { 
            GridPagerItem pager = (GridPagerItem)e.Item; 
            Panel panel = (Panel)pager.FindControl("ctl01"); // for PagerStyle>Mode = "NumericPages" 
            foreach (Control ctrl in panel.Controls) 
            {                 
                (ctrl as LinkButton).Attributes.Add("onClick""PageIndexChanging();"); 
            } 
        }  

Let me know if it helps..
Princy.
Tags
Grid
Asked by
Satyaprakash J
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Satyaprakash J
Top achievements
Rank 1
Share this question
or