2010-12-20 57 views
0

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

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 
+1

“迫切请”---这是可怕的方式来开始你的问题在这里。你必须错过stackoverflow.com和odesk.com/rentacoder.com – zerkms 2010-12-20 07:58:00

+0

欢迎来到SO!我们在这里解决问题时不会“清除”问题。这样,他们可以帮助未来的搜索者。 – Pops 2011-01-07 14:48:15

回答

3

它是因为你直接写在客户端的响应流中。因此,您在页面加载时编写的所有内容都会先写入其他内容。有关调用特定方法的信息,请参阅ASP.NET Page Lifecycle

但在大多数情况下,您不必(也不应该)直接在Response中写入。修改您的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方法分配给控件。

+0

它给出了错误 – Mariam 2010-12-20 08:23:01

+1

这不是一个确切的说法。你现在如何解决你的问题,错误是什么? – 2010-12-20 09:10:40