2013-02-07 51 views
1

我有這個項目,我想從textbox1傳輸數據與會話「sam」在about.aspxlabel。問題是,當我輸入一個數字時,它不顯示在label上。我的問題是I型的東西「ΑριθμόςΕπιβατών:」 textbox(例如數字)之後,我點擊提交我需要獲得關於頁面的數字旁邊的「Ari8mos epivatwn:」來自用戶輸入的文本框的會話數據

Defaultaspxcs。 TXT:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace WebApplication4 
{ 
    public partial class _Default : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void Button1_Click2(object sender, EventArgs e) 
     { 
      string txt = TextBox1.Text; 
      Session["sam"] = txt; 
     } 
    } 
} 

Aboutaspxcs.txt:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace WebApplication4 
{ 
    public partial class About : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      Label1.Text = (string)Session["sam"]; 
     } 
    } 
} 

Aboutaspx.txt:

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" 
CodeBehind="About.aspx.cs" Inherits="WebApplication4.About" %> 

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
</asp:Content> 
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> 
<p> 
    Ari8mos epivatwn : 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
</p> 
</asp:Content> 

https://www.dropbox.com/sh/4ftlddfhqo8n99p/gm-TNvol0S

回答

0

標籤的內容很可能會被寫入兩次,而不是按您期望的順序寫入。通過與asp.net page life-cycle

熟悉自己

開始你會發現,PageLoadRender不久調用。

因此,頁面加載這樣的:

  1. PageLoad標籤文本設置爲某個號碼從您的代碼
  2. 一堆其他的東西
  3. Render設置標籤文本「標籤」來代替,因爲這是你在你的chtml中定義的。

審查你的這部分代碼:

... 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
... 

試試這個:

... 
<asp:Label ID="Label1" runat="server"></asp:Label> 
... 
+0

在有關網頁,我仍然沒有得到的文本框,我輸入數字。 – Vasilis

+0

@ user2052363它代表什麼?另外,當你調試時,你的Page_Load方法被擊中了嗎? – EtherDragon

+0

調試很清楚。它什麼也沒有顯示,就像我沒有會議。 – Vasilis

相關問題