In this code , why does text for response.write appear before the text in the label? Here is the code behind:
protected void Page_Load(object sender, EventArgs e)
{
HttpRequest request = Request;
if (request.QueryString["game"] == "cstrike") Label1.Text = "15000 $";
if (request.QueryString["game"] == "diablo3") Label1.Text = "25000 $";
if (request.QueryString["game"] == "pes2012") Label1.Text = "30000 $";
if (request.QueryString["game"] == "splinterCellConviction") Label1.Text = "75000 $";
Response.Write("<span>Query:<span>" + request.QueryString.ToString());
}
For example , the output looks like this:
Query:
game=cstrike
15000$
why did it output in this order? The “asp label control” is above all the controls on the page :
I expected the output to look like this :
15000$
Query:
game=cstrike
here is the asp.net page code front:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Pricing.aspx.cs" Inherits="queryStringPlay.Pricing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
The normal rendering of the page is being preempted by your call to response.write. Here is the order of events in asp.net http://msdn.microsoft.com/en-us/library/ms178472.aspx
Your call to response.write is basically saying “go ahead and write this value to the stream without waiting for the rest of the rendering pipeline to happen”. Its my opinion that this is bad form and that you should place a literal on the page that contains the 15000$ value. Then have your code just set the text value of that literal.