2010-12-20 58 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