Friday, May 2, 2008

LESSON 1 : ASP.NET CSHARP FOR ABSOLUTE BEGINNERS

These asp.net lessons for absolute beginners. Just copy and paste the code in an editor like Visual Web Developer 2008 Express Edition (it is free) and run it.The simple and best tutorials for asp.net is available at DOTNETSPIDER

Lesson 1a.aspx

<html>
<head>
<title>1a</title>
</head>
<body>

Welcome

</body>
</html>

Lesson 1b.aspx

<%@ Page Language="VB" %>

<html>
<head>
<title></title>
</head>
<body>

Welcome

</body>
</html>

Lesson 1c.aspx

<%@ Page Language="VB" %>

<html>
<head>
<title></title>
</head>
<body>

<%

Response.Write("Welcome")

%>

</body>
</html>

Lesson 1d.aspx

<%@ Page Language="VB" %>

<%
Label1.Text = "Welcome"
%>

<html>
<head>
<title></title>
</head>
<body>

<p><asp:label id="Label1" runat="server" /></p>

</body>
</html>

Lesson 1e.aspx

<%@ Page Language="VB" %>

<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Label1.Text = "Welcome"
End Sub
</script>

<html>
<head>
<title></title>
</head>
<body>

<p><asp:label id="Label1" runat="server" /></p>

</body>
</html>

  • Note :
  • Write the code in between <script> tags is better than writing the code in between <%......%>
  • But writing the code in a separate code-behnd file is better than writing the code inside <script> tags.
Lesson 1f.aspx

<%@ Page Language="C#" %>
<script language="c#" runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
Label1.Text = "Welcome";
}
</script>


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

Lesson1g.aspx : CODEBEHIND


<%@ Page Language="C#" CodeFile="Lesson1g.aspx.cs" Inherits="Lesson1g" %>
<html>
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

Lesson1g.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Lesson1g : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "Welcome";

}
}

Note:

  • The value of Inherits (ie. Lesson1g) in aspx file should match with the value of class ( ie. Lesson1g) in aspx.cs file.
  • The value of CodeFile (ie.Lesson1g.aspx.cs) in aspx file should be name of the code-behind file (ie.Lesson1g.aspx.cs)
  • In this lesson 1g, you need not mug up all the lines. Only the lines in red color were typed by me. The remaining lines are automatically generated. Even in the case of red lines, while typing, INTELLISENSE will guide you properly.
  • asp.net program can be written in vb(ie vb.net),c#,j#,c++. If you have not yet decided the language. There is lot of demand for c#. So, Let us learn c#.




Lesson1f.aspx : CODEBEHIND

<%@ Page Language="VB" CodeFile="Lesson1f.aspx.vb" Inherits="Lesson1f" %>

 

<html>
<head>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>

 

Lesson1f.aspx.vb

Partial Class Lesson1h
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Label1.Text = "Welcome"
End Sub
End Class

No comments:

 
Disclaimer and Copyright