Inline-Code vs Code-Behind

by top54u.com 02 Nov, 2007

 

Inline Code or In-Page Code Approach

The type of coding style used by ASP developers is known as inline coding, inline code or in-page code because that was the only way to develop an ASP page. In ASP Pages scripting code working for generating desired output was intermixed with HTML code to create user friendly pages as well as specific functionality was added to the web pages. In those days inline code was very popular in VB developers because they had hands on experience in writing long vb scripts to create well defined huge asp web sites. But often, the combined intermixed HTML, JavaScript and VB Scripts become ambiguous for maintaining the readability of large web pages. You can design and code ASP .Net web pages using inline code but it becomes difficult to maintain the server side events of all the server controls on a single page.

Add Inline Code to ASP .Net Page and learn how to get current date and time using VB or C# script.

 

Code-Behind Approach

The New ASP .Net Framework has provided the way out to maintain the code for large web pages. Now you can design the HTML code page with .aspx extension separately and maintain the code files for the same .aspx page of VB and C# separately. This style of coding to develop web pages is called Code-Behind. Code Behind approach is a better way to develop and design the .aspx page having basic layout of a web page containing all the necessary controls required for the GUI of the web page. Then include the VB or C# code behind class file for handling the events of controls. This mechanism separates the web page from design layout from the coding part.

Code-Behind Example:

ASPX Page with design layout

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<html>
<head>
    <title>Code-Behind Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" /><br />
        <asp:Label ID="lblname" runat="server"></asp:Label></div>
    </form>
</body>
</html>


Code-Behind File

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        lblname.Text = txtname.Text
    End Sub
End Class

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:21:51 AM




related videos.....
recent posts.....
top54u ezines.....