Powered by: newtelligence dasBlog 1.8.5223.1
Thursday, February 10, 2005
No not that kind of Brain Dump -- I just figured I'd mention this stuff, in case it comes up again/for someone else...
I've been fighting with ASP.net and Visual Studio.net (2003). VS.net pushes code-behind files (aspx.vb or aspx.cs) hard, since they help separate logic and presentation (a good thing). One particular way is by disabling Intellisense (the #A1 best main reason I use VS.net and InterDev before it) in the aspx file itself.
Next problem: Ok, I bought into using code-behind file for UI/logic separation. Unfortunately every little change to the code-behind requires a rebuild, and therefore a restart of the app (logging me out, since I'm using tracking auth in session). So I then have to re-login and find where I was all over again... for each and every change to the code-behind!
Alright, screw the code-behind, I think. back to my own code separation -- one big logic block before the presentation block, with minimal connections between. Big errors! (something about method body, I recall) -- I can't put functions/subs there.
My first discovery: you can use functions/procs in the aspx. You just can't have them inside <% shorthand ASP tags %>-- they only work inside explicit script tags (e.g. <SCRIPT runat="server"></SCRIPT>). Apparently <%%> and <SCRIPT runat="server"></SCRIPT> are no longer equivalent to each other, as they were in Classic ASP.
<%
%>
<SCRIPT runat="server"></SCRIPT>
<%%>
SO, my gears turned and came up with a solution to the mess: a homebrew code-behind. I ripped out the contents of the code-behind, put them in a separate aspx file (inside a <SCRIPT runat="server"></SCRIPT> block), and just include it. This solves the rebuild/restart problem, and still maintains code separation.
Downside: no Intellisense! (since VS.net now only enables it for what it recognizes as code-behind files)
Next discovery: The @Page directive can have an src attribute/property to reference the code-behind file (it normally uses Inherits and Codebehind attributes/properties to enable the code-behind). src does NOT require rebuilding to take effect. It also works with a normal code-behind files, so you get blessed Intellisense. (more info here: Inherits vs. Src vs. Codebehind)
So I now have a solution, just with something like <%@ Page Language="vb" src="report.aspx.vb" inherits="report" %>. (The inherits is still needed for object/class references).
<%@ Page Language="vb" src="report.aspx.vb" inherits="report" %>.
One catch: VS.net complains loudly when it loads a page with this src attribute:
Some further, unrelated discoveries:
Response.IsClientConnected
Option Strict
Remember Me