0

我想在 jquery 滑块的 mouseup 事件中引发服务器端事件。我怎样才能做到这一点?你能给我一个好的起点吗?

我想调用的服务器端代码是

Private Sub LoadBlock(ByVal AA As Integer)
'A lot of stuff here
End Sub

从 Jquery 滑块事件收集的值应作为上述过程中的参数传递

我当前的 JQuery 是

<script type="text/javascript">
    $(document).ready(function () {

        var Country = ['<% =String.Join("', '", arrayString)%>'];

        $('#slider-range-max').slider({
            max: '<%= arrayLength%>',
            min: 0,
            value: '<%= iValue%>',
            slide: function (event, ui) {
                var splitValues = Country[ui.value].split("~");
                $('#lblGame').html(splitValues[0]);
                $('#hpHome').html(splitValues[1]);
            },
            stop: function (event, ui) { }
        });
    });

</script>

最后这不是作业!!!

4

2 回答 2

3
<script type="text/javascript">
    $(document).ready(function () {

        var Country = ['<% =String.Join("', '", arrayString)%>'];

        $('#slider-range-max').slider({
            max: '<%= arrayLength%>',
            min: 0,
            value: '<%= iValue%>',
            slide: function (event, ui) {
                var splitValues = Country[ui.value].split("~");
                $('#lblGame').html(splitValues[0]);
                $('#hpHome').html(splitValues[1]);
            },
            stop: function (event, ui) {
            //bof:AJAX hit
            var path="YourPageName.aspx/NewMethod";
            $.ajax({
                url:path,type:"POST",cache:"false",
                dataType:"json",contentType:"application/json; charset=utf-8",
                data:"{'str1':'Some Temp String'}",
                success:function(response){alert("response is "+response.d);
                },error:function(){
                }
            });
            //eof:AJAX hit
            }
        });
    });

</script>

在后面的代码中:

<System.Web.Services.WebMethod> _
Public Shared Function NewMethod(str1 As String) As String
'make same name of variable as in json data
    'do your server side stuff
    Return "Success"
End Function
于 2013-10-12T22:36:50.237 回答
1

我没有测试过这段代码,但这肯定会对你有所帮助

一键

<asp:Button ID="img_update" runat="server" Text="Submit" style='display:none' OnClick="img_update_Click" />

你的方法非静态方法

 protected void img_update_Click(object sender, EventArgs e)
    {
//your code -behind
    }

现在你的 jquery 看起来像

<script type="text/javascript">
    $(document).ready(function () {

        var Country = ['<% =String.Join("', '", arrayString)%>'];

        $('#slider-range-max').slider({
            max: '<%= arrayLength%>',
            min: 0,
            value: '<%= iValue%>',
            slide: function (event, ui) {
                var splitValues = Country[ui.value].split("~");
                $('#lblGame').html(splitValues[0]);
                $('#hpHome').html(splitValues[1]);
            },
            stop: function (event, ui) {
                 document.getElementById('client id of button').click();
               }
        });
    });

</script>

我希望这能让您更好地了解如何实现非静态方法...... :)

于 2013-10-15T09:37:38.977 回答