I am writing some pages in ASP.NET VB. Based on some database results I need certain pieces of information to display, basically if a column is not null then write out <p>database value</p>. So far, all the databse connection is called in my .aspx.vb file.
Rather than have an asp:label (which creates a <span> not a <p> anyway) I was hoping I could keep all my HTML markup front end, so have some ASP Classic code that looks like:
<%
if results.item("name").value <> "" then
response.write("<p>" + results.item("name").value + "</p>"
end if
%>
The problem with this of course is results is not accessible from the front end.
Possibly this is the wrong approach, maybe someone can suggest an alternative if there are better ways. However, I don't like relying solely on Labels, Panels and other built in elements which create spans, divs, etc respectively.
This might sound silly, but there is a reason for this. I need to get some database content into some javascript. Currently I have to load the content into a span (label) which is hidden by css, and then javascript gets the value of this span. I think this
is a very poor way of doing things so would prefer to be able to write out exactly when I want it without any unexpected markups.
For anyone interested it involved creating a bunch of public variables as the top of the page which I then fill while using my SQL data reader and then can access from the front end ASP Classic code.
Cheers,
Chris
Marked as answer by chricholson on Apr 05, 2011 11:26 PM
chricholson
Member
131 Points
95 Posts
ASP Classic elements with ASP.NET code behind
Apr 05, 2011 12:08 PM|LINK
Hello,
I am writing some pages in ASP.NET VB. Based on some database results I need certain pieces of information to display, basically if a column is not null then write out <p>database value</p>. So far, all the databse connection is called in my .aspx.vb file. Rather than have an asp:label (which creates a <span> not a <p> anyway) I was hoping I could keep all my HTML markup front end, so have some ASP Classic code that looks like:
<% if results.item("name").value <> "" then response.write("<p>" + results.item("name").value + "</p>" end if %>The problem with this of course is results is not accessible from the front end.
Possibly this is the wrong approach, maybe someone can suggest an alternative if there are better ways. However, I don't like relying solely on Labels, Panels and other built in elements which create spans, divs, etc respectively.
This might sound silly, but there is a reason for this. I need to get some database content into some javascript. Currently I have to load the content into a span (label) which is hidden by css, and then javascript gets the value of this span. I think this is a very poor way of doing things so would prefer to be able to write out exactly when I want it without any unexpected markups.
Many Thanks,
Chris
chricholson
Member
131 Points
95 Posts
Re: ASP Classic elements with ASP.NET code behind
Apr 05, 2011 11:26 PM|LINK
Ok scrap that, I've worked it out.
For anyone interested it involved creating a bunch of public variables as the top of the page which I then fill while using my SQL data reader and then can access from the front end ASP Classic code.
Cheers,
Chris