1

我有这个项目,我想从其上textbox1的会话“sam”传输数据。问题是当我输入一个数字时,它没有显示在. 我的问题是我在“Αριθμός Επιβατών:”上输入了一些东西(例如一个数字),然后我点击提交我需要在“Ari8mos epivatwn:”旁边的关于页面上获取数字about.aspxlabellabeltextbox

默认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

Label 的内容很可能被写入了两次,而不是按照您期望的顺序。

首先熟悉asp.net 页面生命周期

你会注意到PageLoad很久以前就被调用了Render

因此,页面加载如下:

  1. PageLoad标签文本设置为代码中的某个数字
  2. 一堆其他的东西
  3. Render而是将标签文本设置为“标签”,因为这是您在 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 回答