Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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
Asp.net Listview不工作的异步回发_Asp.net_Vb.net_Listview - Fatal编程技术网

Asp.net Listview不工作的异步回发

Asp.net Listview不工作的异步回发,asp.net,vb.net,listview,Asp.net,Vb.net,Listview,我有一个列表视图,其中有许多链接按钮。现在,当你点击一个按钮,它会触发一个完整的回发,我想交换它,这样它就只是一个部分回发。似乎它应该足够简单,但无论我做什么,我似乎都无法让它发挥作用。似乎我遗漏了一些明显的东西,但在这一点上,我被难住了 列表视图: <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="False" runat="server"> <ContentTemp

我有一个列表视图,其中有许多链接按钮。现在,当你点击一个按钮,它会触发一个完整的回发,我想交换它,这样它就只是一个部分回发。似乎它应该足够简单,但无论我做什么,我似乎都无法让它发挥作用。似乎我遗漏了一些明显的东西,但在这一点上,我被难住了

列表视图:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="False" runat="server">
<ContentTemplate>
  <section id="basketbox">
    <hgroup class="mainhead">
      <h2>Your basket</h2>
    </hgroup>
    <asp:ListView runat="server" ID="ListView1" OnItemCommand="ListView1_ItemCommand" DataSourceID="SqlDataSource1" DataKeyNames="PartCode">
      <LayoutTemplate>
          <div runat="server" id="itemPlaceholder" ></div>
      </LayoutTemplate>
      <ItemTemplate>
            <h4><%#Eval("Name") %></h4>
            <div class="quantitybox">
              <div class="qtylbl">Qty</div>
              <asp:LinkButton id="QtyDown" CommandArgument='<%#Databinder.Eval(Container.DataItem,"PartCode")%>' CssClass="qtybutton" CommandName="QtyDown" runat="server"><img src="/images/minus.png"></asp:LinkButton>
              <div class="qtybox"><%#Eval("Quantity") %></div>
              <asp:LinkButton id="QtyUp" CommandArgument='<%#Databinder.Eval(Container.DataItem,"PartCode")%>' CssClass="qtybutton" CommandName="QtyUp" runat="server"><img src="/images/plus.png"></asp:LinkButton>
            </div>
      </ItemTemplate>
    </asp:ListView>
  </section>
</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="ListView1" />
</Triggers>
</asp:UpdatePanel>
再说一遍:没有区别

我也试过将其中的大部分结合起来;所有这些都没有产生任何影响


我还应该尝试什么

您的评论听起来好像需要学习很多东西才能使用通用处理程序响应AJAX请求。事实并非如此,你可能具备必要的知识

QtyDown.ashx

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class QtyChangeResponse
{
    public bool Success {get; set;}
    public string Message {get; set;}
}

public class Handler : IHttpHandler
{
    public void ProcessRequest (HttpContext context)
    {
        //pull values from query string
        //update database based on values
        //create response
        var responseObj = new QtyChangeResponse(){Success=true, Message="Qty Updated"};
        context.Response.ContentType="application/json";
        context.Response.Write(JsonConvert.SerializeObject(responseObj));       
    }

    public bool IsReusable
    { get { return false; } }
}
因此,这与Web API控制器大致相同

<asp:LinkButton id="QtyDown" CssClass="qtybutton" runat="server" OnClientClick='QtyDown(<%#Databinder.Eval(Container.DataItem,"PartCode")%>); return false;'><img src="/images/minus.png"></asp:LinkButton>

<script type="text/javascript">
function QtyDown(partCode){
    //use your favorite JavaScript library to gather the quantity and PartCode and make a POST call to QtyDown.ashx?qty={quantity}&partcode={partcode)
}
</script>

功能QtyDown(零件代码){
//使用您喜爱的JavaScript库收集数量和部分代码,并对QtyDown.ashx?qty={quantity}&PartCode={PartCode)进行POST调用
}

更容易支持,比UpdatePanel少很多错误,我已经为您做了很多工作。

在页面声明中将页面设置为异步(没有区别)
这与UpdatePanel完全无关,这是异步/等待支持。
-在listview控件上将ClientMode设置为AutoID(没有区别)
客户端上的ID无关紧要。您是否尝试过将每个链接按钮包装到自己的UpdatePanel中?顺便说一句,我建议您完全放弃UpdatePanel()使用AJAX和@mason我知道UpdatePanels是魔鬼的产物-不幸的是,我正在工作的项目有一个期限太近了,我无法离开并掌握它的Web API。我还没有尝试嵌套更新面板-我会试一试。(感谢你的解释-这两件事我都在一个平台上尝试过。)“这到底有什么用呢”这句话的基础是(在我发飙之后)你不必使用Web API,特别是因为它只在.NET 4.5上运行(但它是理想的)。我也不推荐ASMX,因为该服务基本上是不推荐的。如果我是你,我会做的是设置一些通用处理程序(.ashx)。让他们在Web API中履行控制器的职责。你不会得到很好的模型绑定功能,你需要手动从查询字符串/表单值中提取值。但这一切都应该简单、快速地实现。我知道仅仅使用UpdatePanel来“完成”的诱惑“,但你大概必须支持这段代码,对吧?@Mason是的,我必须支持这段代码-这就是为什么至少在这一点上,我不想为了支持这一项目的这一页而学习一批全新的代码的另一个原因!(此外,当我说最后期限很紧的时候,我的意思是希望它能在下周中期上线。)嵌套的更新面板没有帮助(而且作为一个次要问题,它们也破坏了我的布局!)1)老实说,我可能有很多东西要学——我对.net的知识是零碎的,而且大部分是自学的(因此不可避免地会有一些愚蠢的问题)2)不幸的是,我使用的是vb.net,所以c#解决方案真的没有帮助me@FrustratedWDotNetC#和VB非常接近,因此存在代码转换器,可以完成合理的工作。我使用了其中的一个,并用等效的VB代码更新了我的答案。不,如果你可以处理来自Web表单页面的回发并更新数据库,你可以从通用处理程序。您需要的唯一附加知识是JavaScript。
Imports System.Web

Public Class QtyChangeResponse
    Public Property Success() As Boolean
        Get
            Return m_Success
        End Get
        Set
            m_Success = Value
        End Set
    End Property
    Private m_Success As Boolean
    Public Property Message() As String
        Get
            Return m_Message
        End Get
        Set
            m_Message = Value
        End Set
    End Property
    Private m_Message As String
End Class

Public Class Handler
    Implements IHttpHandler
    Public Sub ProcessRequest(context As HttpContext)
        'pull values from query string
        'update database based on values
        'create response
        Dim responseObj = New QtyChangeResponse() With { _
            Key .Success = True, _
            Key .Message = "Qty Updated" _
        }
        context.Response.ContentType = "application/json"
        context.Response.Write(JsonConvert.SerializeObject(responseObj))
    End Sub

    Public ReadOnly Property IsReusable() As Boolean
        Get
            Return False
        End Get
    End Property
End Class
<asp:LinkButton id="QtyDown" CssClass="qtybutton" runat="server" OnClientClick='QtyDown(<%#Databinder.Eval(Container.DataItem,"PartCode")%>); return false;'><img src="/images/minus.png"></asp:LinkButton>

<script type="text/javascript">
function QtyDown(partCode){
    //use your favorite JavaScript library to gather the quantity and PartCode and make a POST call to QtyDown.ashx?qty={quantity}&partcode={partcode)
}
</script>