2016-07-28 62 views
-2

如何在asp.net中將標籤值傳遞給c#中的會話變量?如何將標籤值傳遞給c#中的會話變量在asp.net中

subtotal標籤顯示的值,但沒有通過任何值會話變量:.session["subtotal"]=subtotal.text;

我下面的代碼可以請你幫#

<%@ Page Title="" Language="C#" MasterPageFile="~/SiteProduct.Master" AutoEventWireup="true" CodeBehind="Checkout.aspx.cs" Inherits="Ecommerce.Checkout" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 
 
    <!-- check out -->  
 
<div class="container"> 
 
\t <div class="check-sec"> \t 
 
\t \t <div class="col-md-3 cart-total"> 
 
\t \t \t <a class="continue" href="Default.aspx">Continue to basket</a> 
 
\t \t \t <div class="price-details"> 
 
\t \t \t \t <h3>Price Details</h3> 
 
\t \t \t \t <span>Total</span> 
 
       <div class="total"> 
 
\t \t \t \t \t <span class="simpleCart_total"></span> </div> 
 
\t \t \t 
 
\t \t \t \t <span>Discount</span> 
 
\t \t \t 
 
       <span class="total1">$00.00</span> 
 
\t \t \t \t <span>Delivery Charges</span> 
 
\t \t \t \t 
 
       <span class="total1">$00.00(free)</span> 
 
\t \t \t \t <div class="clearfix"></div> \t \t \t \t 
 
\t \t \t </div> \t 
 
\t \t \t <ul class="total_price"> 
 
\t \t \t <li class="last_price"> <h4>TOTAL</h4></li> \t 
 
\t \t \t \t 
 
       <div class="total"> 
 
\t \t \t \t \t <span class="simpleCart_total"></span> </div> \t  
 
\t \t \t </ul> 
 
\t \t \t <div class="clearfix"></div> 
 
\t \t \t <div class="clearfix"></div> 
 
\t \t \t <a class="order" href="Checkoutsignin.aspx">Place Order</a> 
 
\t \t \t 
 
\t \t </div> 
 
\t \t <div class="col-md-9 cart-items"> 
 
\t \t \t <h1>My Shopping Bag </h1> 
 

 
      
 
      <%--here cart view start 06/06/2016 --%> 
 
       
 
     
 

 
      
 
       <table style="width:100%;" class="table table-hover"> 
 
        <ul >    
 
      <tr style="width:100%;" > 
 
        
 
       
 
       <td style="width:100%;color:red;background-color:lightblue;margin:10px;display:inline-block;padding:18px;" class="simpleCart_items"> 
 
         
 
       </td> 
 
      </tr> 
 
      </ul> 
 
        
 

 
        <tr > 
 
    <td> </td> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td><h5>Subtotal</h5></td> 
 
    <td> 
 
     
 
     <div><asp:Label ID="subtotal" class="simpleCart_total" runat="server"></asp:Label></div> 
 
     
 
    </td> 
 
</tr> 
 
<tr> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td><h5>Estimated shipping</h5></td> 
 
    <td><div class="simpleCart_shipping"></div></td> 
 
</tr> 
 
<tr> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td><h3>Total</h3></td> 
 
    <td> 
 
     <div id="grandtotal" class="simpleCart_grandTotal"></div> 
 

 
    </td> 
 
</tr> 
 
<tr> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td> </td> 
 
    <td> </td> 
 
    
 
    <td><a class="order" href="Checkoutsignin.aspx">FinalCheckout</a></td> 
 
    <td style="visibility:hidden"> <asp:TextBox ID="myTextBox" runat="server"></asp:TextBox> </td> 
 
    
 
    
 
</tr> 
 

 
    
 
    
 
      </table>   
 

 
      
 
      
 
        
 
      <%-- here cart view end 06/06/2016--%> 
 

 

 
      <%-- This part is close start 07/06/2016--%> 
 

 
\t \t \t \t 
 

 
      <%-- This part is close End 07/06/2016--%> 
 

 

 

 

 

 
\t \t </div> 
 
\t \t <div class="clearfix"> </div> 
 
\t </div> 
 
</div> 
 
<!-- //check out --> 
 
</asp:Content> 
 

+1

Y您沒有在代碼中將值分配給會話,並且您沒有在代碼中顯示您嘗試讀取該代碼的位置。 –

+0

嘗試 Session [「subtotal」] = subtotal.Text; – Sak

+0

後面的代碼在哪裏? –

回答

0

試試這個:

 <asp:Label ID="subtotal" Text="SomeText" class="simpleCart_total" runat="server"></asp:Label> 
     <%Session["subtotal"] = subtotal.Text; %> 
+0

我的字體結束端顯示正確的值,但後面的代碼不會將此值控制到會話變量請幫助:<%Session [「subtotal」] = subtotal.Text; %>我的代碼在後面:if(!IsPostBack) { Session [「subtotal」] = subtotal.Text; } – salahuddin20364

+0

如果你想在你的服務器端使用Session [「subtotal」],這是可以的。但爲了確保初次刷新你的頁面,並在服務器端查看Session [「subtotal」] – AmirhosseinYari

+0

謝謝你的評論,我曾多次工作過這個過程,但它不適用於我目前的項目。我已經嘗試了很多方法,但仍然存在問題..如果有任何解決方案,請告訴我。 – salahuddin20364

相關問題