Problem with onclientslide function

5 posts, 1 answers
  1. Marlou
    Marlou avatar
    27 posts
    Member since:
    Jun 2012

    Posted 14 Aug 2009 Link to this post

    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";  
          } 
  2. Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 17 Aug 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marlou
    Marlou avatar
    27 posts
    Member since:
    Jun 2012

    Posted 17 Aug 2009 Link to this post

    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 :(
  5. Answer
    Tsvetie
    Admin
    Tsvetie avatar
    1517 posts

    Posted 19 Aug 2009 Link to this post

    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.
  6. Marlou
    Marlou avatar
    27 posts
    Member since:
    Jun 2012

    Posted 19 Aug 2009 Link to this post

    Hi!

    Thank you for helping! :) It works!

    Regards,
    Marlou
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017