开发者

The session contents do not appear in the content of the second page

I put this sessions in the page load of the page I want them to be displayed in, but the session contents appear in the top of my website not in the content what is the problem????

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


Its because you write directly in the response stream for the client. So everything you write at Page Load is written before anything else. Please see the ASP.NET Page Lifecycle for informations when specific methods are called.

But in the most cases you don't have to (and should not do) write directly in the Response. Modify your aspx-File, so you have server-side controls for your stuff, like:

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

And than use in the Page_Load method:

lblUsername.Text = Session("Username")

So forget about the Response.Write. Modify your ASPX-Page so you have regular HTML inside it. Use server-side controls for your content and then assign the proper values to your controls int he Page_Load method in code behind.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜