473,586 Members | 2,683 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using inline stmts vs Page_Load event

What is the consensus on putting ASP.NET code inline in the html doc versus
using code behind and C#. I find it confusing when pages include code in
both places. For example, using DataBinder.Eval statements in the HTML. Is
there an advantage to doing any coding within the HTML page? It seems
cleaner to do all coding in the webform but I am an admitted DOTNET newbie

Thanks
Nov 17 '05 #1
3 1359
As long as it is not INSIDE the HTML (IOW, it is above the first <html>
tag), it is fine to put your CodeBehind class definition in the same file as
the Page Template. Mixing Code and Content is never a good idea.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Jack Frost" <ex****@exc.dom > wrote in message
news:3f******** **@newspeer2.td s.net...
What is the consensus on putting ASP.NET code inline in the html doc versus using code behind and C#. I find it confusing when pages include code in
both places. For example, using DataBinder.Eval statements in the HTML. Is there an advantage to doing any coding within the HTML page? It seems
cleaner to do all coding in the webform but I am an admitted DOTNET newbie

Thanks

Nov 17 '05 #2

"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
As long as it is not INSIDE the HTML (IOW, it is above the first <html>
tag), it is fine to put your CodeBehind class definition in the same file as the Page Template. Mixing Code and Content is never a good idea.

I agree but many of the MS code samples (IBuySpy for one) employ this
technique. If I can't look to MS for guidance on best practices, where can
I look? Do you have book recommendations ?

Thanks again.
Nov 17 '05 #3
> I agree but many of the MS code samples (IBuySpy for one) employ this
technique.
Not sure what "this technique" refers to.
If I can't look to MS for guidance on best practices, where can
I look? Do you have book recommendations ?
You certainly CAN look to MS for guidance on best practices. The .Net SDK,
which is the only "book" I recommend, has a good number of articles on best
practices. You can download the .Net SDK for free from the following URL:

http://www.microsoft.com/downloads/d...displaylang=en

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Big Things are made up of
Lots of Little Things.

"Jack Frost" <ex****@exc.dom > wrote in message
news:3f******** **@newspeer2.td s.net...
"Kevin Spencer" <ke***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
As long as it is not INSIDE the HTML (IOW, it is above the first <html>
tag), it is fine to put your CodeBehind class definition in the same
file as
the Page Template. Mixing Code and Content is never a good idea.
I agree but many of the MS code samples (IBuySpy for one) employ this
technique. If I can't look to MS for guidance on best practices, where

can I look? Do you have book recommendations ?

Thanks again.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2670
by: Studio P.M. | last post by:
Dear colleagues, I kindly ask the C# developers community to help me to REALLY understand the Page_Load event, so to REALLY have it under control. Reason for this question is that I cannot anymore accept passively the behavior of the “Web Form Designer” automatically generated code because of the fact that, in some circumstances (that I...
0
960
by: Jessard | last post by:
Hi, Which will be executed first? A Page_Load event in the aspx.vb file or an inline vb.net serverside script in the html? Jesse
6
3413
by: Anders M | last post by:
I'm trying to use Inline-code to call Page_load, Page_Init or Page_PreRender methods. I've also got a code behind c#-file. I can define inline methods for buttons and so on...that works fine. But when I try to call Page_load, Page_Init or Page_PreRender methods it doesn't work. Non of the methods get's triggered !?
12
3807
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it (the oleDBConnection on global.asa.vb) at the other aspx pages ?
4
3964
by: Seraph | last post by:
Again, I'm rather new here, so if I fail to follow any etiquette, please forgive me and let me know what I've done wrong, but I think this might interest quite a few people. One of my colleaques was endeavoring to create a custom user control to make things a bit simpler, but she noticed that her Page_Load eventhandler was firing twice. So...
3
1656
by: Nathan Sokalski | last post by:
I am using the AddHandler statement to add a CheckedChanged event handler to a series of RadioButtons that I create in a loop. However, the handler is not being called for a reason I cannot determine. What is the problem? Here is my code: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load...
2
1049
by: tshad | last post by:
Is there a way to put inline data in a label? For example, I would normally do something like this to put a name that I have in my session variables in my asp:label: Name.Text = Session("FullName") .... <asp:Label ID ID="Name" runat="Server">
1
2958
by: rockdale | last post by:
Hi, I have a masterpage and on the page_load event I Populate my mainmenu from database. I the page_load event of my content, I am trying to programmly select the menuitem that represent current content page, but as you know, the page_load event is fired backward, the content page_load fires first then followed by the master page...
6
1870
by: tshad | last post by:
I was looking at a page that showed how to set up a custom event and it seems to work ok. But I am not sure how I would use it. How would I subscribe to it. There is actual action (such as pressing a button or changing text in a textbox). It gets set up and on the user control on my web page I can see the event from intellisense. So it...
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.