Forum Moderators: open
Top of Page
-----------
<%
1. Check for postback, do form processing
2. Do any code that needs to be done before this page is displayed
%>
<html>
Display code and <%=var%> tags go here
</html>
----------------------
End of script
I've used this method for 2 years now, and it's worked pretty well for me.
However, in reading a lot of ASP.NET books, it seems they want to change my style. I have to put my dynamic content in <asp:label>s to be displayed, they want me to run my postback and pre-display code in a function that's set to runat=server (which doesn't let me <%=display_this_variable%> within the HTML).
It's a big change, and I feel if anything it's less readable than my previous code, as well as harder to edit layout stuff, despite what some books say to the contrary. What's wrong with my previous method? Am I missing something with the new method?
<p><%=var1%></p>
<p><%=var2%></p>
<p><%=var3%></p>
Each time you go from html to vbscript and back is called a context switch. Context switches are slow. So you may be better off doing this:
<%
Call Response.Write("<p>" & var1 & "</p>")
Call Response.Write("<p>" & var2 & "</p>")
Call Response.Write("<p>" & var3 & "</p>")
%>
Or even:
<%
Call Response.Write("<p>" & var1 & "</p><p>" & var2 & "</p><p>" & var3 & "</p>")
%>
But in ASP.NET, you have to get with the program, and do it the way they tell you. The ASP.NET way is to separate the running code from the HTML.