Two ways of doing programming in ASP.NET

Today’s topic of discussion is based on the ways ASP.NET providing facility for doing programming. Actually there are two ways; you can do programming in ASP.NET. One is In-Line and second is Code-Behind. All the programmers have their own style of doing programming. If you are working on programming languages like asp, php then you will prefer In-Line coding and if you are working on windows platform or if you are using windows languages like Visual Basic etc., then code behind would be their choice of doing programming.

Coding in Code-Behind Part:

Let us see what the differences are there if we do programming using both the ways. First of all we will discus how to do programming using Code-Behind. If you choose Code-Behind part for programming purpose then first question comes in our mind that how to transfer in Code-Behind part? For that you just have to double-click on the form, by double-clicking on which one new window will be opened and that part is called Code-Behind part. Now before starting programming in Code-Behind part you have to import required namespace for your application to run and that you can import in public section of Code-Behind part which is available above the declaration of class, to clearly understand this concept see the example given below.

Imports System.IO

Public Class WebApplication1
Inherits System.Web.UI.Page
End Class

If you are doing programming using Code-Behind part and you want to generate some output when user clicks on control then for that you have to draw the control on the form and by double-clicking on that control you will be transferred to Code-Behind part of your application where you have to write your code. When you are doing programming using Code-Behind part then you always have to keep one thing in mind is that you can not use html control for doing programming in Code-Behind part and if you do so than before starting programming on this control you have to convert that control in ASP. Net’s control and for that you just have to double click on the control it will ask you to convert control in ASP.NET control if you select yes then control will be converted to ASP.NET control and then after you can start programming on that control in Code-Behind part.

Coding in In-Line part:

Now let us see the differences if we do In-Line coding in ASP.NET. As I said earlier that if you are doing programming using languages like asp and php etc. then it would be the easier for you to do programming in In-Line portion. To start doing programming in In-Line part just click on html button available at the bottom of the form where you can see html coding of your form. When you start programming in asp you have to write the starting and ending scriplet tag which are <% and %>, you always have to write your asp coding between these two tags and the same way you have to write scriplet tag <% and %> if you are doing programming in In-Line part of ASP.NET, you have to write your all coding between these two tags only if you try to write coding out side these tags than you will get run time error and some time design time error too. Here the concept of importing namespace will remain same means; you have to import required namespace before starting programming but the method is different. To understand this very clearly see the below given example.

<%@Import NameSpace="System.Io" %>
Your coding must comes between these tags.

By viewing above example you can understand how it is differ to write programming using both ways. Furthermore if you want to generate output when user clicks on the button then you have to draw one button on the form but at this time button would be html submit button but you can not write coding on any ASP.NET control. As you can see in above example, that all the coding line is place between starting and ending scriplet tag which are <% and %> because if you never follow this rule than you will receive error.

After given full discussion on above topic I hope you can write your coding using any part of the ASP.NET.

(Posted By Aden)

Web development tips, marketing strategies and AccuWeb Hosting news sent to your inbox.

Live Chat with our Executive