Proper way to write code?

J

John

This is a simple, newbe question.
In Asp/VB there are 2 ways to display message on page load
I can double click on aspx page and aspx.vb file is created:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Here I can crete my message

Response.Write("Page loaded")

End Sub



Alternatively, I can create script which will do same thing:

<script language="vb" runat="server">

Sub Page_Load(Sender As Object, E As EventArgs)
Response.Write("page loaded")
Edn Sub

</script>



Why there are 2 way to do same thing? Which one is correct/better? Are there any differences?
 
R

Remy

The first way with the aspx way is nicer, because it splits the GUI
layer from the code layer. Otherwise you mix HTML, ASP and VB code all
in one file an it will get a mess eventually. In ASP.NET 2.0 they even
go one step further and put all code that was generated by the IDE in a
third file.
In terms of function it makes not difference, neither really in terms
of performance.

Remy Blaettler

Helping you collaborate better!
www.collaboral.com
 
J

JIMCO Software

Remy said:
In terms of function it makes not difference, neither really in terms
of performance.

It actually does make a great difference. If you place the code inline,
that page will get compiled the first time it is browsed into one DLL.
Every other page like that will also get compiled into one separate DLL. If
you have a lot of pages, what you end up with is a large number of small
DLLs strewn all over memory. This greatly increases your chances of seeing
an OutOfMemory condition due to a failure to allocate a contiguous block of
memory to grow the managed heap.

By using code-behind (and setting debug = false in your web.config), you
alleviate this problem because your application is batch compiled. That
means that instead of one DLL for each page, you have one DLL for each
folder that contains all of the types in that folder.

I see this problem a lot.
 
R

Rosanne

Also, if you are displaying large amounts of data, it's better to le
the server do the work. We originally were importing all the data t
the client via XML and traversing the data there with inline code.
When the XML blob got too big, the application was dragging. So, w
moved everything to code behind and it's running just fine.

Just my thoughts..
 
S

Scott Allen

It actually does make a great difference. If you place the code inline,
that page will get compiled the first time it is browsed into one DLL.

Webforms with inline code will still participate in batch compilation.
You can even mix code-behind forms and inline code forms in the same
directory and the runtime will batch compile to one dll (assuming the
conditions are right for batch compilation).
 
J

JIMCO Software

Scott said:
Webforms with inline code will still participate in batch compilation.
You can even mix code-behind forms and inline code forms in the same
directory and the runtime will batch compile to one dll (assuming the
conditions are right for batch compilation).

Right you are. I had my mind on using the Src attribute. Thanks for the
correction.
 
J

John

Thanks all for response.
Also, what I noticed, with code behind, if I enter, for instance, Imports
System. = I will selection of all valid options.
It looks like I cannot get this if using inline code, unless my settings are
wrong.

john
 

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

No members online now.

Forum statistics

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

Latest Threads

Top