Page view counter

Slider extender, client events

Last post 12-19-2008 10:28 AM by Danny117. 6 replies.

Sort Posts:

  • Slider extender, client events

    11-29-2006, 9:54 AM
    • Loading...
    • DanNsk
    • Joined on 03-30-2006, 11:59 AM
    • Novosibirsk/Russia
    • Posts 6
    • Points 20
    I have slider extender on a page , which is bound to a hidden field, and has some textbox as an target control.
    Slider extender has valueChanged event, is there any way to attach my handler to it ?
    My idea was $find('controlId').add_valueChanged( function() {} ); , but doesn't work.

     
  • Re: Slider extender, client events

    11-29-2006, 4:22 PM
    • Loading...
    • Garbin
    • Joined on 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,501
    • Points 7,396
    • ASPInsiders
      TrustedFriends-MVPs

    Hi,

    you can give an id to the behavior using the BehaviorID property in the extender control. Then, you can write

    $find('behaviorID').add_valueChanged(function() { alert('value changed!'); });
     

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Slider extender, client events

    11-30-2006, 12:27 AM
    • Loading...
    • DanNsk
    • Joined on 03-30-2006, 11:59 AM
    • Novosibirsk/Russia
    • Posts 6
    • Points 20
    I forgot to tell that i'm trying to add this script dynamically, in a Page_Load event handler of a page
    so the only working solution i've found -


    string script = "Sys.Application.add_init(function() {\n" +
    " var slider1 = $find('" + SliderExtender1.BehaviorID + "');\n" +
    " if (slider1) slider1.add_valueChanged(function() { alert('value changed!'); });\n" +
    " });\n";

    ScriptManager.RegisterStartupScript(Page, GetType(), "StartupValuesFunction", script, true);

  • Re: Slider extender, client events

    01-04-2007, 11:32 AM
    • Loading...
    • huenemeca
    • Joined on 08-02-2002, 2:19 PM
    • Posts 179
    • Points 832

    Hello,

    I am trying to get this to work so that I can have the slider use a AJAX call to report it's position to the system.  But when I use $find('BehaviorID') I get null.  I am actually using the behaviorID of the slider extender control.  Can you show me an example of this working? 

    Also, is there any plans to add the valueChanged event to the Extender so that I can just say ValueChanged='myjavascriptFunction'?  It seems like a control in the AJAX toolkit should have this sort of functionality.

    Thanks,
    Mike
     

    Filed under:
  • Re: Slider extender, client events

    01-04-2007, 12:01 PM
    • Loading...
    • Garbin
    • Joined on 09-17-2004, 12:35 PM
    • Sassari, Italy
    • Posts 1,501
    • Points 7,396
    • ASPInsiders
      TrustedFriends-MVPs

    Hi,

    please check the following example: 

    <%@ Page Language="C#" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Slider Example</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager ID="TheScriptManager" runat="server"></asp:ScriptManager>
        
        <asp:TextBox ID="txtSlider" runat="server"></asp:TextBox>
        <asp:Label ID="lblSliderBound" runat="server"></asp:Label>
        
        <ajaxToolkit:SliderExtender ID="SliderExtender1" runat="server"
            TargetControlID="txtSlider" BoundControlID="lblSliderBound" BehaviorID="sliderBehavior"
            Steps="3"></ajaxToolkit:SliderExtender>
        
        <script type="text/javascript">
        <!--
            function pageLoad(sender, e) {
                var slider = $find('sliderBehavior');
                slider.add_valueChanged(onValueChanged);
            }
            
            function onValueChanged(sender, e) {
                alert('Value changed!');
            }
        //-->
        </script>
        </form>
    </body>
    </html>
     

    Alessandro Gallo | Blog | My book: ASP.NET AJAX In Action
  • Re: Slider extender, client events

    01-04-2007, 9:11 PM
    • Loading...
    • huenemeca
    • Joined on 08-02-2002, 2:19 PM
    • Posts 179
    • Points 832
  • Re: Slider extender, client events (get event into javascript)

    12-19-2008, 10:28 AM
    • Loading...
    • Danny117
    • Joined on 12-16-2008, 9:30 AM
    • Royal Oak Michigan USA
    • Posts 1,831
    • Points 10,532

    It's not open but here's another method.  Why didn't I find this yesterday when I was looking for "Slider" "javascript"

    Here's method two to get the slider event into a javascript after that i'ts upto you.

    $addHandler($get("txtr"), "change", updateslide);

    txtr is the id of the textbox

    change is the event

    updateslide is the name of the javascript to call ajax will pass in an object.

     

    <asp:TextBox ID="txtr" runat="server"></asp:TextBox>

    <cc1:SliderExtender ID="SliderExtender1" runat="server" Enabled="True"

    RaiseChangeOnlyOnMouseUp="false" Minimum="0" Maximum="255"

    TargetControlID="txtr">

     

     

    <script type="text/javascript">

    function updateslide(x) {

    // what ever you want to do.... 

    // var dec = x.target.value;

    // var hex = parseInt(dec).toString(16);

    // if (hex.length < 2) {

    // hex = "0" + hex;

    //

    }

     

    $addHandler($get("txtr"), "change", updateslide);

    </script>

    Good Luck



Page 1 of 1 (7 items)