Running code when viewing aspx code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,

Our team has a very strange problem. I hope anybody can help.

We have a class called webpage and all our aspx-pages bases on it. Then we
have a SYS.IO.File Class which have a function. This function checks the hash
value of some ini-files. If the hash value is not valid then the function
throws an error.
Imagine we are editing the code behind file of an aspx-page. If we now want
to view the aspx-code we double click the aspx-file in the project explorer
and then there occurs the exception of the function in the class SYS.IO.File.
The application is not running.
We don't have any idea why the webpage is calling the function in this moment.
Is there any possible reason why code is running when viewing the aspx-code
while the web-application is not running?
 
Assuming that you are working with VS.NET

If you open any aspx file in VS.NET by double clicking in Solution Explorer,
VS will open
that page in design mode, As per my understanding the design view is nothing
but
like a web browser, so it executes the code there and shows the error.

I too have faced some strange errors when opening a aspx page in design view
you can change this options in tools>options window to open any aspx page
in html view.

Have a try, as i'm not sure about this answer.
Atleast it will help you in going closer towards the problem.
 
Hi Matthias,

the reason why your code is executed is that VS.NET calls OnInit method of
the page (but not only, also code in properties is executed...), when you
try to open the aspx in Desing Mode.

There is a workaround.

You need to put your code inside this IF:
if (Site == null || !Site.DesignMode)
{
// this is the normal situation
}
else
{
// this is the VS.NET DesingMode situation
}

HTH

Bye,
Stefano
 

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

Back
Top