Marina wrote:
Start putting all your server side code in a codebehind file. That way you
compile that code and see errors right away. And if you're using vs.net for
development, you also get the benefits of intellisense, etc.
One option, of course, would be using labels etc. and setting their
values from the code behind file. This is how I did it when I started
with ASPX, but this turned out to be rather cumbersome when not using
the designer (which I don't use because it keeps on destroying my HTML
code, hope whidbey will solve this)...
With labels, databinding would also work - but this is also totally not
"compile-safe" (typo in the databinding expression, and your gone...)
What I'm doing right now is using properties in the code-behind file,
which I use in the ascx/aspx-controls. This looks something like this:
<TABLE border="0" cellspacing="0" cellpadding="4">
<TR>
<TD><%= Name %> someText <%= SomeCountX %></TD>
</TR>
</TABLE>
This is much more readable than putting labels in there for Name and
AuditoriumCount, and using labels doesn't even get me any further
concerning the "compile-time security": when I change the IDs of the
labels in the ascx/aspx-file, they may not be automatically be changed
in the codebehind file which will get me NullReferenceExceptions at
runtime (I don't use the designer at all anymore, as it always destroys
my HTML-code).
However, this blows up my codebehind file significantly, and still when
there's a typo in the ascx/aspx-file, I get something like this:
===== START included error message ====
Server Error in '/' Application.
--------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'SomeCountX' does not exist in
the class or namespace 'ASP.DetailsPage_ascx'
Source Error:
Line 11: <TABLE border="0" cellspacing="0" cellpadding="4">
Line 12: <TR>
Line 13: <TD><%= Name %> someText <%= SomeCountX %></TD>
Line 14: </TR>
Line 15: </TABLE>
Source File:
http://localhost/UI/PageContents/DetailsPage.ascx Line: 13
===== END included error message ====
So, this does help me a little bit (misspelling a property is not such a
simple mistake), but blows up my codebehind files significantly. E.g.
when I use a typed dataset (with a couple of columns), I have to repeat
each property of the dataset in my codebehind file - it would be much
more elegant putting this directly into the page (e.g.
dsMyDataSet.MY_TYPED_COLUMN) than having a lot of getters for this, like
public string MyTypedColumnValue {
get { return dsMyDataSet.MY_TYPED_COLUMN; }
}
kind regards,
david