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

Problem with onclientslide function

4 Answers 64 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Marlou
Top achievements
Rank 1
Marlou asked on 14 Aug 2009, 09:36 AM
Hi!

I've got a problem with the onclientslide function. What I am trying to do is set the value of the slider in a label. The problem is that the slider and the label are in the PagerTemplate of an gridview.

So when the gridview has only 1 page, the pagertemplate doesn't exist. I can add the javascript function in codebehind and that works fine for a normal page.

But my gridview is in an updatepanel which is in a usercontrol. The first time when the whole page is rendered, the gridview is empty so there is no pagertemplate, after i search the results will be shown in the gridview and the gridview has a pager template. But because it's an async postback, the whole page doesn't render and i cant register javascrip, so the function will not work.

this is my pagertemplate inside the gridview control
<PagerTemplate> 
  <telerik:RadSlider ID="slider" runat="server" Orientation="Horizontal" Skin="Office2007"   
            AutoPostBack="true" OnValueChanged="Slide_Changed" DataValueField="lblpage" OnClientSlide="clientSlide" /> 
  <label>Pagina </label> 
  <asp:Label ID="SlideLabel" runat="server" /> 
  <asp:Label ID="lblpage" runat="server" Text='<%# " van " + ItemsGridView.PageCount %>' /> 
</PagerTemplate> 

This is the function where i try to add the javascript to the slider

protected void ItemsGridView_DataBound(object sender, EventArgs e)  
    {  
      GridViewRow rowPager = ItemsGridView.BottomPagerRow;  
      if (rowPager != null)  
      {  
        RadSlider slider = (RadSlider)rowPager.Cells[0].FindControl("slider");  
        slider.MinimumValue = 1;  
        slider.MaximumValue = ItemsGridView.PageCount;  
        slider.Value = ItemsGridView.PageIndex + 1;  
        Label sliderLabel = (Label)rowPager.Cells[0].FindControl("SlideLabel");  
        sliderLabel.Text = (ItemsGridView.PageIndex + 1).ToString();  
 
          
          
        string script = @"
         <script type='text/javascript'>
           function clientSlide(sender, eventArgs)
          {                
            var myLabel = document.getElementById('" + sliderLabel.ClientID + @"');
            myLabel.innerHTML = sender.get_value();             
          }
        </script>";  
 
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "clientslider", script);  
        slider.OnClientSlide = "clientSlide";  
      } 

4 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 17 Aug 2009, 08:22 AM
Hi Marlou,
In this case you can register the script not with the Page, but with the UpdatePanel that wraps the GridView. I created a simple page that demonstrates how you can do this - please find it attached.

Regards,
Tsvetie
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marlou
Top achievements
Rank 1
answered on 17 Aug 2009, 08:30 AM
I've tried this but the problem is that my gridview is in a usercontrol which is on a page that has a master page. I can have only one scriptmanager and that one is in my master page. I don't know how to talk to this scriptmanager :(
0
Accepted
Tsvetie
Telerik team
answered on 19 Aug 2009, 08:05 AM
Hello Marlou,
I am not using the ScriptManager instance to register the script, but a static method of the ScriptManager class:
ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "clientslider", script, true); 

That is why you need not talk to the ScriptManager on your master page.

All the best,
Tsvetie
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marlou
Top achievements
Rank 1
answered on 19 Aug 2009, 09:10 AM
Hi!

Thank you for helping! :) It works!

Regards,
Marlou
Tags
Slider
Asked by
Marlou
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Marlou
Top achievements
Rank 1
Share this question
or