Precompiling ASPX/ASCX for discovering compile-time errors...

  • Thread starter Holger (David) Wagner
  • Start date
H

Holger (David) Wagner

Hi Group,

I've searched the Web for precompilers that compile ASPX/ASCX pages just
like it can be done with JSPs, but so far, I've only found approaches
targetted at increasing the performance. What I'd like to do this for,
however, is discovering compile-time errors during my normal build.

Currently, just a typo in a Property name goes unnoticed until the page
is hit the first time which is not particularly satisfying (this is like
opening an application and actually using/testing it to find syntax
errors)... is there any option in MS VS.NET 2003 to activate such a type
of (pre-)compilation?

I know this is included in Whidbey, but we can't use this, yet...

kind regards,
david
 
C

Cowboy \(Gregory A. Beamer\) [MVP]

I am not sure I understand you. Even precompile will not catch typos in the
controls when you are talking about the UI of the page (ie, the tags in the
ASPX). Not having full intellisense is certainly one of the issues; which I
believe can be conquered, if it is worth the time.

There are other options, however.

1. Create a server control instead, which allows you to use the property
sheet
2. Add reference in your code behind to the control. Then, you can
programatically set the property using Intellisense

You can use a product like NAnt (Source Forge open source project), but
precompile will still not catch tag typos.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
M

Marina

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.
 
L

Lau Lei Cheong

It's a bit strange, but typo errors in property name must be shown when you
"Build" your project.("Build" -> "Build solution") You can even press "F5"
to run you project for checking runtime error...
 
H

Holger (David) Wagner

Marina said:
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
 
H

Holger (David) Wagner

Cowboy said:
I am not sure I understand you. Even precompile will not catch typos in the
controls when you are talking about the UI of the page (ie, the tags in the
ASPX). Not having full intellisense is certainly one of the issues; which I
believe can be conquered, if it is worth the time.

There are other options, however.

1. Create a server control instead, which allows you to use the property
sheet

I avoid the designer whenever I can as it destroys the HTML code... at
first, I used the designer all the time, with a lot of WebControls... by
now, I've converted to using <%# ... %> and <%= ... %> whenever I can.

When Whidbey stops messing with the HTML code, I might convert back
again, but right now I have switched the design view off...
2. Add reference in your code behind to the control. Then, you can
programatically set the property using Intellisense

You can use a product like NAnt (Source Forge open source project), but
precompile will still not catch tag typos.

I'm not concerned with tag typos... actually, I think VS.NET issues
warnings when the HTML-code is incorrect. Does NAnt support compiling
aspx-pages? And ascx-controls? That would be just what I need...

kind regards,
david
 
H

Holger (David) Wagner

Lau said:
It's a bit strange, but typo errors in property name must be shown when you
"Build" your project.("Build" -> "Build solution") You can even press "F5"
to run you project for checking runtime error...

Is there a setting for this somewhere? I'm talking about using
properties of the codebehind-class in the ASCX/ASPX-page, which my
VS.NET (2003) never notices...

kind regards,
david
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top