2016-01-06 93 views
0

我需要幫助;)我使用來自代碼後面的代碼,通過Asp.net和htmlGenericControl填充ul。Asp.net VB Webform。如何從代碼隱藏的ul列表中獲取li項目

列表中的項目出現,這些項目是可跌落和可排序成不同的uls槽jQuery排序和connectedSortable函數。這工作正常。

例如,我有3個列表。 UnorderdLists(ul's)A,B和C. 列表A填充了一些項目。現在我可以將這些列表項從列表A拖放到列表B或列表中。

現在我需要幫助如何查看或獲取(在/在codebehind)哪個項目在列表B或C?

信息:

  • 我不使用bulletlist因爲我覺得dropable /排序會給我帶來些麻煩吧。
    • 我的ul's已經添加了runat =「server」,我的li必須有這個嗎?
+0

你可以發佈你到目前爲止嘗試過的代碼嗎? –

+0

嗨thx的評論。我只有三個連接列表.. soo沒有太多的代碼。我現在會嘗試巴洛的建議:) – mio

回答

0

當我使用自定義或不標準控件,我更喜歡在一個自定義的方式(與炭分離器例如值)使用隱藏字段和存儲數據。

您可以通過Javascript/JQuery填充您的隱藏字段在您的特定事件,然後從代碼隱藏您可以閱讀隱藏的字段。

更新例如

這只是一個方法可行,但更簡單的可能是JQuery的AJAX。

webform.aspx

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="webform.aspx.vb" Inherits="ajax_test.webform" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title></title> 

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 


    <script type="text/javascript"> 

     $(document).ready(function() { 

      $('#send').click(function() { 
       $('#<%= HFTest.ClientID %>').val($('#theValue').val()); 
       __doPostBack('<%= btn_force_async.ClientID %>',''); 
      }); 

     }); 

    </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
     <div> 
      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> 


      <script type="text/javascript"> 

       Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler); 
       Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler); 

       function BeginRequestHandler(sender, args) { 
        // Fire before the AJAX request 

       } 
       function EndRequestHandler(sender, args) { 
        // Fire after the AJAX request 
        if ($('#<%=HFReturnMessage.ClientID %>').val() == 'ok') { 
         alert('ok!'); 
        } else { 
         alert($('#<%=HFReturnMessage.ClientID %>').val()); 
        } 
       } 

      </script> 




      <input id="theValue" type="text" value="ok" /> 
      <input id="send" type="button" value="send value" /> 



      <asp:UpdatePanel ID="UPDHiddenFields" runat="server" UpdateMode="Conditional"> 
       <ContentTemplate> 

        <asp:HiddenField ID="HFTest" runat="server" /> 

        <asp:HiddenField ID="HFReturnMessage" runat="server" /> 

       </ContentTemplate> 
       <Triggers>  
        <asp:AsyncPostBackTrigger ControlID="btn_force_async" EventName="click" /> 
       </Triggers> 
      </asp:UpdatePanel> 
      <asp:Button ID="btn_force_async" runat="server" style="display:none;"/> 

     </div> 
    </form> 
</body> 
</html> 

webform.aspx.vb //代碼隱藏

Public Class webform 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

     If IsPostBack Then 

      If HFTest.Value = "ok" Then 
       HFTest.Value = "" 
       HFReturnMessage.Value = "ok" 
      Else 
       HFTest.Value = "" 
       HFReturnMessage.Value = "error, the HFTest is not ok ! " 
      End If 

      UPDHiddenFields.Update() 'Update hidden field panel on client side 


     End If 

    End Sub 

End Class 

希望這有助於你。

+0

嗨,thx的答案,我會嘗試隱藏的領域的東西:) – mio

+0

嘿。我向你的代碼添加了你的建議。但是,如果我按一個按鈕來從一個項目獲取隱藏的數據。頁面重新加載和jQuery添加的數據消失了。 – mio

+0

我不完全知道你的情況,但如果你需要不再重新加載頁面,那麼你必須使用AJAX請求。 – Baro