【问题标题】:The session contents do not appear in the content of the second page会话内容不会出现在第二页的内容中
【发布时间】:2010-12-20 07:52:59
【问题描述】:

我把这个会话放在我希望它们显示的页面的页面加载中,但是会话内容出现在我的网站顶部而不是在内容中是什么问题????

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

    Response.Write("<h1 align=center>Radiation Calculator</h1>")
    Response.Write("<br>Hi Mr/Mrs " & Session("Username"))
    Response.Write("<br>The following results have been sent to your Email " & Session("Email"))
    Response.Write("<br>Air Traveling Distance " & Session("Air Traveling Disance") & " Km")
    Response.Write("<br>You have selected the following Factors: " & Session("Factor0") & " . " & Session("Factor1") & " . " & Session("Factor2") & " . " & Session("Factor3") & " . " & Session("Factor4") & " . " & Session("Factor5") & " . " & Session("Factor6") & " . " & Session("Factor7"))
    Response.Write("<br>Total Radiation " & Session("Total Radiation") & " mrem")
    Response.Write("<br>Your Life Reduction would be: " & Session("User Life Expectancy In Minutes") & "Mintues " & "  " & Session("User Life Expectancy In Hours"))



End Sub

【问题讨论】:

  • "Urgent Please" --- 这是在这里开始你的问题的糟糕方式。你一定错过了stackoverflow.com和odesk.com/rentacoder.com
  • 欢迎来到 SO!在这里解决问题时,我们不会“删除”问题。这样,它们可能会帮助未来的搜索者。

标签: asp.net vb.net visual-studio-2008 session


【解决方案1】:

这是因为您直接在客户端的响应流中写入。因此,您在 Page Load 上编写的所有内容都是在其他任何内容之前编写的。调用具体方法时请查看ASP.NET Page Lifecycle

但在大多数情况下,您不必(也不应该)直接在响应中写入。修改你的 aspx 文件,这样你就可以对你的东西进行服务器端控制,比如:

<h1 align="center">Radiation Calculator</h1>
<br>Hi Mr/Mrs <asp:Label id="lblUsername" runat="server" />
...

比在 Page_Load 方法中使用:

lblUsername.Text = Session("Username")

所以忘记 Response.Write。修改您的 ASPX 页面,以便在其中包含常规 HTML。为您的内容使用服务器端控件,然后在后面代码中的 Page_Load 方法中为您的控件分配适当的值。

【讨论】:

  • 这不是一个真正准确的说法。你现在是如何解决你的问题的?错误是什么?
猜你喜欢
  • 2012-08-09
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-03
  • 1970-01-01
相关资源
最近更新 更多