The problem I'm having, is that my page is outputting my data, before the <html> ... </html> tags. So, my stuff comes out, and then IIS is sending out the normal HTML content.
How can I have my page output data inside the html and body tags ?
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strArr() As String : strArr = Split(Request.QueryString("Code"), ",")
Dim strTableName As String, strSQLStatement
Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim lngTemp As Long : myConnection.Open()
Select Case strArr(0)
Case "1" : strTableName = "tblMasterHeaders"
Case "2" : strTableName = "tblSecondaryHeaders"
Case "3" : strTableName = "tblThirdHeaders"
Case "4" : strTableName = "tblThirdHeaders"
End Select
lngTemp = strArr(0)
If Not strTableName = vbNullString Then
strSQLStatement = "SELECT * FROM " & strTableName & vbCrLf
You are approaching ASP.NET in the wrong way. You are looking at as if it was ASP 3.0. You shouldn't need to use response.write statements if you are coding correctly. I have only seen one or two instances where this would be necessary, but I am sure even in those cases it could have been avoided with a little thought.
You are just writing out tables, which .Net has a control for you to use. Drop the table control on your page, then you can programatically (sp?) add table rows to it when looping through a datasource if you want. What this does is allow you to completely seperate code and content, something you are not doing now. When you do this, you can change the style of the table on the aspx page, but the code will never have to be touched. This is the goal.
We talked about this at a local study/focus group, and it is amazing how often people do this because of past habbits. What we all strive for is NO html in our code. This is extremely easy once you get used to it.
I'd go along with that last bit completely. For a single value, you could look to use a label on the webform to write the value to.
For the above, try looking up databind() and datagrid in the msdn library...
Please rate this post if it was useful for you!
Please try to search before creating a new post,
Please format code using [ code ][ /code ], and
Post sample code, error details & problem details
And if you truly feel you just can't do it with complete seperation (which shouldn't be the case), use a literal control and assign your html to its text property. It renders out its text as html, unlike the label.
I'm having to reconsider this. For instance I have an ImageList control that is basicly just a .net wrapped javascript array of ImageObjects one of it's methds is
Code:
public string ImageTag(int index);
and about 10 or 15 overloads. It returns a string containg an image tag for the specified indexed image. I use response.write to write it on the page. What would be the way to do this?
edit:
n/m sorry I didn't read everything before I started running my mouth......
Last edited by Magiaus; Mar 28th, 2004 at 07:18 PM.
Okay. I shouldn't be using HTML myself.
Then tell me how I should go about doing this then.
I have attached a zip with 4 files.
Basically, the index, and then going 3 levels deep to a product.
How would I implement something that looked like that, without requiring the user to have the .net framework or some other complicated thing installed?
This is what baffles me you see...
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
None of the "Web Forms" controls require the .NET framework.
I would suggest learning proper ASP.NET first through a book or tutorial. I found the book "Teach Yourself ASP.NET in 21 Days" very useful and easy to follow. (Most of the stuff was VERY basic but the Datagrid info was pretty useful)
well, the bit about not using html is not correct. one of the major goals of .net though is provide seperation of asp code and html code. so edit your html and edit your code but don't mix them together via <% %>. use codebehind or server side script blocks for server code and do html like always. And frankly I use Response.Write plenty..... but I use in a script block and if I'm not using Response.Write I use an HtmlWriter.
the funny thing is you'll see a lot of ASP.NET books combining both <%script > and HTML in the same listing in their examples.
I think this is why some people go this way. Myself, I always found it confusing considering I really only started dynamic web development since the dawn of ASP.NET.