Label, TextBox and Button Web Server Controls in Asp.Net

Label control: 

This control can be used to display static text at required position with in webform

 

Properties: 

Id: specify name to control, The control be accessed with in server side programming using name[id] 

Text: it can be used to set or get label content[text] 

Backcolor: seclect color 

Note:label name should start with lbl, it is considered as naming standard for label in realtime implementation.

 

Creating website to work with label control 

Goto visual studio 

Start->run->devenv 

It will display main window of visual studio 

File menu->new->website->visual c#->select asp.net empty website 

Weblocation->e:\aspnet\labelsite[drive:\dir\websitename]

 

Visual studio create a folder with website name, in this folder website related files will be placed

 

Creating asp.net webpage into labelsite 

Goto view menu and select solution explorer 

Right click on website path and select add newitem 

Select webform 

Give name as default.aspx  

it will display following code

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head 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>

 

Goto design view 

Goto view menu and select toolbox 

Expand standard tab and double click on label control

 

Setting control properties 

Select label1 present on webform and select f4 key 

->it will display label properties within properties window 

Id-lbltitle 

Back color-chose color 

Bold-true 

Size-x-large 

Double click on default.aspx webform window 

[it will display code view with page load sub program declaration]

 

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Web; 

using System.Web.UI; 

using System.Web.UI.WebControls;

 

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

{ 

    protected void Page_Load(object sender, EventArgs e) 

    { 

        lbltitle.Text = "webserver control accessed with in server side programming" 

    } 

}

 

Goto contrl F5

 

Output

Top of Form

 

webserver control accessed with in server side programming

 

 

 

 

 

Bottom of Form

 

 Note: page load sub program will be executed once webpage is loaded with all the controls

 

2)page load sub program will be executed towards each client request to webpage  

3)web server controls will produce html content[html control] to client browser once webpage execution is finished with in server system

 

Text box control: 

This control can be used to accept data from user 

Properties: 

1)id-specify name to control, Text box name should start with txt 

2)text-it can be used to set/get textbox data 

3)textmod-specify mode for textbox, This provides 3 options 

           1)singleline 

           2)multiline 

           3)password

 

Button control: 

This control can be used to perform page submission 

Properties: 

1)id-specify name , button name should start with btn 

2)text 

3)pastbackurl-specify web page name (or) url to which data to be submitted

 

Page submission: 

Client submitting data to website is called “page submission”. 

Asp.net supports 2 types of page submissions 

1.cross page submissions 

2.post back submission

 

Cross page submission: 

One webpage submitting data to another webpage is called “cross page submission”. 

This requires 2 webpages 

1.source webpage: this webpage will accept data from user 

2.destination webpage: this webpage will read data submitted by source webpage 

Request object can be used to read data i.e 

i)Request.From[“controlid”]->post arrangement reading 

ii)Request.querystring[“controlid”]->get arrangement reading 

 default arrangement in asp.net is post

 

creating website to work with cross page submission: 

Goto visual studio 

Start->run->devenv 

It will display main window of visual studio 

File menu->new->website->visual c#->select asp.net empty website 

Weblocation->e:\aspnet\crosspagesite[drive:\dir\websitename] 

Visual studio create a folder with website name, in this folder website related files will be placed 

 

Add webform

Goto view menu and select solution explorer 

Right click on website path and select add newitem 

Select webform 

Give name as login.aspx

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml"> 

<head runat="server"> 

    <title></title> 

</head> 

<body> 

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

    <div> 

    </div>

    </form> 

</body> 

</html>

 

Goto design part 

Goto view menu and select toolbox 

Expand standard tab and place 2 label control and 2 text boxes and button 

Top of Form

 

 Note: arrange controls using spacebar and enter key        tom of Foaaa

 

 

 

Label 1 properties: 

Id-lblusername 

Text-username

 

Label 2 properties: 

Id-lblpassword 

Text-password

 

Textbox1 properties: 

Id-txtusername 

 

Textbox2 properties: 

Id-txtpassword

Textmode-password

 

Button 1 properties: 

Id-btnlogin 

Text-login 

Postbackurl-validate.aspx

 

Creat one more asp.net webpage into website 

->rightclick on website path and select add newitem->select webform 

    Give name->validate.aspx 

->goto design view and place label control 

Double click on validate.aspx webform

 

using System; 

using System.Collections.Generic; 

using System.Linq; 

using System.Web; 

using System.Web.UI; 

using System.Web.UI.WebControls;

 

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

{ 

    protected void Page_Load(object sender, EventArgs e) 

    { 

        string uname = Request.Form["txtusername"]; 

        string pwd = Request.Form["txtpassword"]; 

        Label1.Text = "welcome to" + uname; 

    } 

}

 

Right click on login.aspx and select set as start page.

Goto contrl F5 

 

Output: 

Enter name, password it will be display following

welcome toraghu