Freelance Jobs

Inline Coding and Code-Behind Technique

Hello Friends, What's up, Today's i am here to tell some thing about the way of coding.

Here we have 2 ways to code:- Inline Coding and Code-Behind Model.

But First we have to knowledge about the File Types and its extenstion's

1) Web Form .aspx

2) AJAX Web Form .aspx

3) Master Page .master

4) AJAX Master Page .master

5) Web User Control .ascx

6) Web Service .asmx

While working with Inline coding you get only the above exentsion of the file

But in case of Code Behind technique you get presentation and code file separate

means one file type has 2 extenstions for eg.

Web Form .aspx(Design Mode) .aspx.cs(Code Mode)


Inline Coding:-


Friends who are familiar with simple ASP, can easily grasp up the meaning of Inline coding.

You remember in simple ASP, we can bind our logical code and presentational code in the single page.

Here logical code stands for whatever we write in the <script> and </script>, and the presentational code stands for that we write in the <body> and </body> .

To ensure that you are using the Inline code, you simple select the page type form the "Add New Item" Dialog Box and make sure that the "Place Code in Separate File" checkbox is

unchecked.

"Add New Item" option appear when you choose "Website" option from the menubar.

Simple program example with the help of Inline Coding.

Write the Following Code within the head tag.

<script language="C#" runat="server">

protected void Button1_Click(object sender, EventArgs e)

{

Label1.Text = "Hello " +TextBox1.Text;

}

</script>

Write the Following Code within the body tag.

<form id="form1" runat="server">

<div>

What is your name?<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

</div>

</form>

*******************************************************************************


Code Behind Model Technique


In the code behind technique, we get presentational code and business (logical) code in the different file extentions.

What so ever we have to present we use presentational file extenstion for eg. "Default.aspx" and if we want to present the logical code the we use the file extenstion for eg. "Default.aspx.cs"


Simple program example with the help of Code Behind Techinque.


To ensure that you are using the Inline code, you simple select the page type form the "Add New Item" Dialog Box and make sure that the "Place Code in Separate File" checkbox is

checked.

"Add New Item" option appear when you choose "Website" option from the menubar.

But default this checkbox is already checked.

Write the following code in the Default.aspx page

<form id="form1" runat="server">

<div>

What is your name?<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

</div>

</form>

Write the following code in the Default.aspx.cs file.

using System;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{ }

protected void Button1_Click(object sender, EventArgs e)

{

Label1.Text = "Hello " + TextBox1.Text;

}

}

Thanxs to read, its my pleasure that you give your precious time for read my article plus code snippet.

0 Comments:

Post a Comment



ONLINE JOBS