1

textbox1私は、セッション「sam」を使用してデータを転送したいこのプロジェクトを持っていabout.aspxますlabel。問題は、数字を入力しても に表示されないことlabelです。私の問題は、「Αριθμός Επιβατών:」textbox(たとえば、数字) に何かを入力し、[送信] をクリックした後、「Ari8mos epivatwn :」の隣のページで数字を取得する必要があることです。

デフォルトの aspxcs.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;
        }
    }
}

aspxcs.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"];
        }
    }
}

aspx.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

4

1 に答える 1

0

ラベルのコンテンツが 2 回書き込まれており、期待どおりの順序ではない可能性があります。

asp.net ページのライフサイクルを理解することから始めます。

PageLoadがかなり前に呼び出されていることに気付くでしょうRender

したがって、ページは次のように読み込まれます。

  1. PageLoadコードの数値に設定されたラベル テキスト
  2. その他いろいろ
  3. Render代わりに、Label テキストを「Label」に設定します。これは、chtml で定義したものであるためです。

コードのこの部分を確認します。

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

代わりにこれを試してください:

...
<asp:Label ID="Label1" runat="server"></asp:Label>
...
于 2013-02-07T22:54:00.497 に答える