Solved

understanding asp.net code behind

Posted on 2006-06-13
3
399 Views
Last Modified: 2013-11-25
Hi

I want to clarify my understanding of asp.net code behind. I am going to write down my understanding. I would appreciate it if you could correct bits or add on bits I am missing.

Code behind doesnt mean anything to the asp.net engine. It is something specific to Visual Studio. It tells VS where the code behind for a web page is.

When you make solution in VS all of the vb files are compiled into a dll and put in the application bin directory.
When you put this on the website, the asp.net engine looks for all classes it needs in the dlls in the bin directory
Will it look in all the dlls in the bin directory?
Does it look anywhere else?

When you have a dll you dont need to upload the vb files. In fact, when you have a dll you shouldnt upload the vb files because they take precedence and the asp.net engine will compile the vb files every time the application starts and ignore the dll

If you upload the vb files and not a dll, the asp.net engine will compile the vb files dynamically into a dll every time it runs the application.

However, I DONT UNDERSTAND THIS:
I was experimenting with my website and I deleted the dll. If what I have said is correct, asp.net should have compiled all the vb files into a dll and the application should have run ok. However, it didnt and I got a could not load type message. Why is this????

You can use the code behind model without visual studio. YOu can give asp pages a src attribute which tells asp.net where to look for the class file

If you use a src attribute, does the asp.net engine compile the vb files into a dll? I dont think it does. I believe if you want to compile the files you need to use the vbc compiler.


Any comments to add to  my understanding are welcomed

thanks
andrea
0
Comment
Question by:andieje
  • 2
3 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 300 total points
ID: 16895017
>> Will it look in all the dlls in the bin directory?
Yes.

>> Does it look anywhere else?
It will look in the GAC if it doesn't find it in /bin. It may look in other paths that you specify in your config (at least, it will with .Net 2.0).

>> If you upload the vb files and not a dll, the asp.net engine will compile the vb files dynamically into a dll every time it runs the application
You shouldn't upload the .vb files. The ASP.Net engine will compile the IL code stored in the DLL using the JIT compiler the first time it is run. The DLL has to be present on the server, the ASP.Net engine will not compile your .vb files.

>> You can use the code behind model without visual studio. YOu can give asp pages a src attribute which tells asp.net where to look for the class file
True. But trying to do it freehand is more trouble than its worth.
0
 
LVL 25

Accepted Solution

by:
dstanley9 earned 200 total points
ID: 16895038
Here's an MSDN article from Fritz Onion (who knows what he's talking about):

http://msdn.microsoft.com/msdnmag/issues/06/01/ExtremeASPNET/

To answer your specific question:

Unless you're using the SRC attribute, ASP.NET will need to compiled DLLs to acquire the type that the page inherits from (even if the source code is there).  If you use the SRC attribute, it will compile the source on-the-fly (NOT into a static DLL) and load the types from the assembly in memory.  There may be some caching involved so that it doesn't re-compile unless there's a change in the source code, but I don't have first-hand knowledge of that.
0
 
LVL 25

Expert Comment

by:dstanley9
ID: 16895043
Sorry, that should be:

ASP.NET will need THE compiled DLLs to aqcuire...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now