Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
Code output before <html> tag not in <body>
Old 10-06-2008, 11:38 AM Code output before <html> tag not in <body>
Junior Talker

Posts: 2
Trades: 0
Hey

I'm new to asp.net, but experienced with php.

I'm having a little trouble getting my head around this language.

I've written a script that pulls in values from a database and then loops through the results creating a positioned, styled div for each.

The problem is, the code that has been created by the script is being output above the page <html> tag and not ni the body.

Can anybody help me out and shed some light on the subject.

Cheers.

My code is here:

Code:
 <%@ Import Namespace = "System.Data.SqlClient" %> 
 
 <html> 
 <head>
 <title>Equalitree!</title>
 <style type="text/css">

div {
text-align:center;
color:#fff;
}

#tree {
width:600px;
height:600px;
border:1px solid black;
background: transparent url(tree.png) no-repeat;
}

.leaf-green {
background: transparent url(leaf-green.png) no-repeat;
width:50px;
height:30px;
position:relative;
}

.leaf-red {
background: transparent url(leaf-red.png) no-repeat;
width:50px;
height:30px;
position:relative;
}

.leaf-blue {
background: transparent url(leaf-blue.png) no-repeat;
width:50px;
height:30px;
position:relative;
}

</style> 
 </head>
 <body> 
 
       <script id="tree" language = "VB" runat ="server"> 
         
         Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

             Dim ConnStr As String

             ConnStr = "Data Source=STEPHEN\SQLEXPRESS; Integrated Security=SSPI;"
             ConnStr = ConnStr + "Initial Catalog=tree"

             Dim conn As SqlConnection = New SqlConnection(ConnStr)

             conn.Open()
        

              ' Declarations  
    
             Dim MyCommand As System.Data.SqlClient.SqlCommand
             Dim MyDataReader As System.Data.SqlClient.SqlDataReader
          
             
              ' Open the connection and execute a SQL Statement  
                         
             MyCommand = New System.Data.SqlClient.SqlCommand
             MyCommand.Connection = conn
             MyCommand.CommandText = "SELECT id, colour, number, leftpos, toppos, info FROM leaves"
             MyDataReader = MyCommand.ExecuteReader()
         
             Response.Write("<div id=tree>")
             
             
              ' Loop through the DataReader and write out each entry  
             While MyDataReader.Read
                  Response.Write("<div class=leaf-" & MyDataReader.Item("colour") & " left=" & MyDataReader.Item("leftpos") & "px top=" & MyDataReader.Item("toppos") & "px>" & MyDataReader.Item("number") & "</div>")
             End While
         
             Response.Write("</div>")
             
             ' Clean Up  
             MyDataReader.Close()
             MyDataReader = Nothing
             MyCommand = Nothing
             conn.Close()
             ConnStr = Nothing
             
         End Sub
    </script> 


 </body> 
 </html>
Stephen

Last edited by keeps21; 10-06-2008 at 12:03 PM..
keeps21 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-06-2008, 12:21 PM Re: Code output before <html> tag not in <body>
Junior Talker

Posts: 2
Trades: 0
Solved,

Remove the <script> and Sub Page_load

and wrapped the code in <% %>
keeps21 is offline
Reply With Quote
View Public Profile
 
Old 10-06-2008, 07:54 PM Re: Code output before <html> tag not in <body>
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
This would be far easier in ASP.NET, rather than ASP that's being run on with the .NET framework.

Use server controls. Put a literal where you want all your divs to go, and in the Page_Load event handler, set the literal's text property.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Code output before <html> tag not in <body>
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13486 seconds with 12 queries