Solved

understanding asp.net code behind

Posted on 2006-06-13
3
394 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

20 Experts available now in Live!

Get 1:1 Help Now