Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在ASP.NET中使用JQuery进行滑动切换_C#_Jquery_Asp.net_Slidetoggle - Fatal编程技术网

C# 在ASP.NET中使用JQuery进行滑动切换

C# 在ASP.NET中使用JQuery进行滑动切换,c#,jquery,asp.net,slidetoggle,C#,Jquery,Asp.net,Slidetoggle,我想在单击按钮时使用jQuery在ASP.NET中滑动切换项目符号列表。隐藏的C#代码将通过调用web服务并显示数据来更新项目符号列表 我必须在C代码完成后从C代码调用jQuery函数吗?有人举个例子来说明吗 这是我的代码,我将保持简单: 页面代码: <asp:BulletedList runat="server" id="resultsList"> </asp:BulletedList> <asp:Button runat="server" Text="Searc

我想在单击按钮时使用jQuery在ASP.NET中滑动切换项目符号列表。隐藏的C#代码将通过调用web服务并显示数据来更新项目符号列表

我必须在C代码完成后从C代码调用jQuery函数吗?有人举个例子来说明吗

这是我的代码,我将保持简单:

页面代码:

<asp:BulletedList runat="server" id="resultsList">
</asp:BulletedList>
<asp:Button runat="server" Text="Search" id="searchBtn" 
onclick="searchBtn_Click" />
第页的jQuery代码:

$("#searchBtn").click(function () {
        $("#resultsList").slideToggle('slow', function () {
            //do something
        });
});

虽然它不起作用。是因为我没有从C#code behind调用jQuery代码吗?

将下面的代码添加为searchBtn\u Click方法的最后一个字符串:

ClientScript.RegisterStartupScript(this.GetType(), "ToogleResultsList", string.Format("$('#{0}').slideToggle('slow', function () { alert('Foo!'); });", resultsList.ClientID), true);
试试这个解决方案

$("#searchBtn").click(function () {

  if(!$("#resultsList").data("listBound")){

  $.ajax({
    url: "urlWhichWillReturnListMarkUpOrJsonResult",
    succcess: function(response){
       //If the response is just the requried markup
       $("#resultsList").html(response).slideToggle('slow');
       //If the response is a json result then you have to write a logic to read the response and create the required markup for the list and append that markup to resultList container and then call slideToggle method.

       //Once the list is populated set at flag using data attributes so that next time when u click u dont have to make ajax call but just slideToggle it
      $("#resultsList").data("listBound", true);
    }
  });
}
else
{
    $("#resultsList").slideToggle('slow');
}
});

当您在页面加载上加载列表时,请从服务器或按钮单击?@ShankarSangoli on page load我不接触列表,因此它实际上是空的。我只在单击按钮时在服务器端向其添加数据。是否在单击按钮时进行AJAX调用以获取列表信息?@ShankarSangoli我尚未实现AJAX调用。每次单击按钮都会返回完整的帖子。然后需要进行ajax调用获取列表,绑定列表,然后滑动切换列表。非常感谢,我使用了一种非常简单的web服务方法。但对于一个更复杂的方法来说,它不是。我认为这可能是由于方法运行时的延迟(需要几秒钟才能完成)。我通过json返回一个字符串列表,我很确定我有正确的jQuery来打印它们,但是由于某种原因请求一直失败。是的,当然,没问题。因为它确实回答了我的问题。看来我现在有一个稍微不同的问题,所以如果我不能很快找到答案,我可能会在以后开始一个新问题。谢谢。如果我能侥幸逃脱,我真的不想这样称呼这个脚本,但是谢谢你提供的信息。
$("#searchBtn").click(function () {

  if(!$("#resultsList").data("listBound")){

  $.ajax({
    url: "urlWhichWillReturnListMarkUpOrJsonResult",
    succcess: function(response){
       //If the response is just the requried markup
       $("#resultsList").html(response).slideToggle('slow');
       //If the response is a json result then you have to write a logic to read the response and create the required markup for the list and append that markup to resultList container and then call slideToggle method.

       //Once the list is populated set at flag using data attributes so that next time when u click u dont have to make ajax call but just slideToggle it
      $("#resultsList").data("listBound", true);
    }
  });
}
else
{
    $("#resultsList").slideToggle('slow');
}
});