简体   繁体   English

为什么我的ASP.NET jQuery Rad Radlider箭头单击事件无法触发?

[英]Why is my ASP.NET jQuery RadSlider arrow click event not firing?

I'm using the Telerik RadSlider with jQuery 1.10.2. 我正在使用带有jQuery 1.10.2的Telerik RadSlider。 Currently I am capturing 2 events: 目前,我正在捕获2个事件:

  1. OnClientValueChanged: Fires when either the up/down arrow handles are clicked, or the drag slider is in the process of being moved. OnClientValueChanged:单击上/下箭头手柄或拖动滑块正在移动时触发。
  2. OnClientSlideEnd: Fires when the drag slider has finished moving (but does not fire when the arrow handles are clicked). OnClientSlideEnd:在拖动滑块完成移动时触发(但在单击箭头手柄时不触发)。

My question is how can I detect when only the up/down arrow handles are clicked? 我的问题是如何仅单击向上/向下箭头手柄时才能检测到? Obviously I could just hook into the OnClientValueChanged (1st event above) and call the function hooked up to the OnClientSlideEnd (2nd event), but since I am doing calculations and saving values to the database each time the OnClientSlideEnd is triggered, it would be incredibly inefficient to do the calculations and save these values each time the slider handle is dragged. 显然,我可以挂接到OnClientValueChanged(上面的第一个事件)并调用连接到OnClientSlideEnd的函数(第二个事件),但是由于我每次都在进行计算并将值保存到数据库中,因此触发OnClientSlideEnd的过程非常令人难以置信每次拖动滑块手柄时都无法有效地进行计算并保存这些值。

Here is my current RadSlider setup. 这是我当前的RadSlider设置。 Please note that the handles are generated dynamically, but on inspecting the element in Chrome, it has a class of "rslHandle": 请注意,句柄是动态生成的,但是在检查Chrome中的元素时,它具有“ rslHandle”类:

 $(document).ready(function myfunction() { $('.rslHandle, .rslHorizontal, .RadSlider').live('click', 'body', function () { alert('arrow clicked'); }); }); 
 <telerik:RadSlider ID="radSliderTest" runat="server" CssClass="CustomSliderLook" OnClientValueChanged="OnClientSlideChanged" OnClientSlideEnd="OnClientSlideEnd" MaximumValue="100" TrackMouseWheel="true" Width="300px" /> 

I've tried the outdated "live click", "on click", and just the plain ol' "click" method and none have triggered. 我已经尝试过时的“实时单击”,“单击”,只是普通的“单击”方法而没有触发。 Looking through Telerik's documentation for events on the RadSlider, I haven't been able to find anything for the arrow change events other than what is posted here . 浏览Telerik的文档以了解RadSlider上的事件,除了这里发布的内容之外,我没有找到其他有关箭头更改事件的信息 Thanks very much for your help! 非常感谢您的帮助!

Ok I found the solution. 好的,我找到了解决方案。 It worked by capturing the mouseup event like so: 它通过捕获mouseup事件来工作,如下所示:

 $(".rslHandle").live('mouseup', function (e) { alert('arrow clicked'); }); 

I just tried the click() jQuery way of attaching to the click event: 我只是尝试了将click()jQuery附加到click事件的方法:

    function pageLoad() {
        $telerik.$(".rslHandle").click(function () { alert(1); });
    }

which uses the Sys.Application.Load (preferred for IScriptControls like this). 它使用Sys.Application.Load(像这样的IScriptControls首选)。

or 要么

    $telerik.$(document).ready(function () {
        $telerik.$(".rslHandle").click(function () { alert(1); });
    });

where an anonymous function is attached in the document.ready jQuery event. 在document.ready jQuery事件中附加了匿名函数的位置。

Both use the jQuery Telerik provide. 两者都使用jQuery Telerik提供。

You can cascade the selectors and/or use the OnClientLoad event of the slider itself so you can know which is the HTML element where the slider is created. 您可以层叠选择器和/或使用滑块本身的OnClientLoad事件,以便可以知道创建滑块的HTML元素是哪个。

I am not sure, however, why using the built-in events is not OK with you. 但是,我不确定为什么不能使用内置事件。 If you need the final value, regardless of how many times the end user changes it, why not simply use the radSliderTest.SelectedValue property on the server ? 如果您需要最终值,无论最终用户更改了多少次,为什么不简单地在服务器上使用radSliderTest.SelectedValue属性呢? Ultimately, the page will be POST-ed so you can get the rest of the textboxes, dropdowns, etc., so you can use this moment to get the slider value on the server without any additional code. 最终,页面将被POST编辑,因此您可以获取其余的文本框,下拉列表等,因此您可以利用这一刻来获取服务器上的滑块值,而无需任何其他代码。 The slider also offers the AutoPostBack property so when the user changes the value, it can POST the page and fire the OnValueChanged server event. 滑块还提供AutoPostBack属性,因此,当用户更改值时,它可以发布页面并触发OnValueChanged服务器事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM