How to disable the slider?

Last post 11-07-2008 12:43 PM by TheShantyDweller. 2 replies.

Sort Posts:

  • How to disable the slider?

    09-04-2007, 8:12 AM
    • Member
      4 point Member
    • Yash1508
    • Member since 06-22-2007, 6:00 AM
    • Posts 3

    I have a slider extender which is created dynamically. In certain situations, I want the slider disabled i.e. the user should not be able to move the handle. I have tried Enabled and ReadOnly properties but that does not work.

    Can anybody please tell how it can be disabled, if at all it can be?

    Thanks 

  • Re: How to disable the slider?

    09-06-2007, 6:06 AM
    Answer

    Hi Yash1508,

    My understanding of your issue is that you want to disable the slider which is dynamically created on the server side.  If I have misunderstood, please let me know.

    As far as I know , there's no support property or functions. Also Enabled and ReadOnly properties are not working.  My solution is removing all the handers of the SliderExtender by using $clearHandlers(), so it seems disabled. Here is the whole sample which you can disable and enable the Slider Control on the client side. We suggest you wholly copy it into your project and have a test.

    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:TextBox ID="Slider1" runat="server" AutoPostBack="false" style="right:0px" Text="0"/>
            <ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server"
                BehaviorID="Slider1"
                TargetControlID="Slider1"
                Minimum="-100"
                Maximum="100"
                BoundControlID="Slider1_BoundControl"
                Steps="5" />
           
            <input id="btnDisable" type="button" value="Disable" onclick="disableSlider()"/>
            <input id="btnEnable" type="button" value="Enable" onclick="enableSlider()" disabled="true"/>
            <script type="text/javascript" language="javascript">
                function disableSlider(){
                     $clearHandlers($find('Slider1')._handle);
                     $clearHandlers($find('Slider1')._railElement);
                     $get('btnDisable').disabled = true;
                     $get('btnEnable').disabled = false;
                }
                function enableSlider(){
                     $addHandlers($find('Slider1')._handle,
                        {
                            'mousedown': $find('Slider1')._onMouseDown,
                            'dragstart': $find('Slider1')._IEDragDropHandler,
                            'drag': $find('Slider1')._IEDragDropHandler,
                            'dragend': $find('Slider1')._IEDragDropHandler
                        },
                        $find('Slider1'));
                       
                    $addHandlers($find('Slider1')._railElement,
                        {
                            'click': $find('Slider1')._onRailClick
                        },
                        $find('Slider1'));
                    $get('btnDisable').disabled = false;
                    $get('btnEnable').disabled = true;
                }
            </script>
        </form>
    </body>
    </html>

    I hope this help.

    Best regards,

    Jonathan

     
    Jonathan Shen
    Microsoft Online Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: How to disable the slider?

    11-07-2008, 12:43 PM

    I have referred to this post as a means to solve my problem:

    http://forums.asp.net/p/1154395/1895548.aspx

     

     I realize this post is really old and has been solved...I also used this code as a starting point for my own application.  Anyways, My App disables all sliders on a report read-only page.
    My code works in Firefox but will not work in IE.  I think it is a issue of when I call this.  when my javascript is called the Slider AJAX Control's events are not properly set up, so when I go to disable/clear the javascript event handler I recieve an error because the javascript handler has not been created yet.  All of my AJAX sliders are created dynamically in the Page_Init event.  If anyone has knows at what point in time in the Page Load process that I should be running my code to disable the sliders please let me know.  Thanks in advance for any help!


    I was originally using the ClientScript.registerStartUpScript function but that wasn't working in Firefox.

     

     

    ASP C# CODE:

    //Page_PreRender
        protected void Page_PreRender(object sender, EventArgs e)
        {
            string javascriptToCall = "";
            Table table = (Table)plhTable.FindControl("tblEvalFormReport");
           
            //disable all sliders if read only view
            if (readOnly)
            {
                TextBox slider;
                //loop through all elements
                for (int i = 1; i <= 75; i += 2)
                {
                    //create slider control
                    slider = EvalForm.findTableControl("q" + i.ToString(), table);

                    javascriptToCall += "disableSlider('" + slider.ID + "'); ";
                }

                //Inject onload all disableSliders function calls into onload event
                HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("masterbody");

                body.Attributes.Add("onload", javascriptToCall);
            }
        }

     

    public static TextBox findTableControl(string controlID, Table tbl)
        {
            TextBox control = (TextBox)tbl.FindControl(controlID);
            return control;
        }

     

    JS CODE:

     

    function disableSlider(slider)
    {
        //alert(slider);
        $clearHandlers($find(slider)._handle);
        $clearHandlers($find(slider)._railElement);
    }
Page 1 of 1 (3 items)
Microsoft Communities