Category Archives: ASP.Net Example

change password form in asp net c#

In previous post we have learned how to create simple login form and create registration form in asp.net using sql database with c# language.

In this asp.net post, we will learn how to create a change password form for already registered user. For change password user first need to register with detail and get username and password. After register user has to login with his username and password. if username and password march then change password  form loaded to user screen and user can change his password by verifying current password.

change password form in asp.net c#

change password form in asp.net c#

First create a sql table for store user registration detail. we have here created sql table “UserMst” like below:

Here is the sql script for UserMst table:

CREATETABLE[dbo].[UserMst]
(

[ID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Name] [nvarchar](50) NULL,
[SurName] [nvarchar](50) NULL,
[City] [nvarchar](50) NULL,
[Email] [nvarchar](50) NULL,
[Password] [nvarchar](50) NULL,

)

change password form in asp.net c#

change password form in asp.net c#

The html source code for change password form design.

The design asp.net form layout is:

change password form in asp.net c#

change password form in asp.net c#

Here, we first check the use current password, if matches then user can make new password or  we can also say change password.

we user required field validator control for all three textboxes and user compare validator for compare new password and confirm password field in change password asp.net example.

The c# code for change password button.

In above change password asp.net example we use  session[“uname”] in update sql query for change password. When user login in to system with his username and password at that time if credential match then store username or email in session[“uname”].

create simple registration form in asp.net with database c#

In previous asp.net post we have learned how  to create dynamic login form in asp.net using database. Now, in this tutorials we will  learn how to create simple registration from in asp.net using database.

create simple registration form in asp.net with database

create simple registration form in asp.net with database

 Video tutorials for ASP.Net Registration Form


For create registration from first, create a table in sql server for registration. we have here created table “UserMst” in sql server for store the registration data.

The sql table “UserMst” like :

create simple registration form in asp.net with database

create simple registration form in asp.net with database

Open Visual Studio and create a new web site –>> Design asp.net web form for user registration.

The HTML Source code of registration form :

The design of web form like :

create simple registration form in asp.net with database

create simple registration form in asp.net with database

Here, we use validation control for all textboxes in registration form. We use required field validator for all the textbox to check whether it is empty or not. and use Regular Expression Validation for check valid email textbox.

First add namespaces for sql connection.

using System.Data;
using System.Data.SqlClient;

The C# code for register button click :

Download ASP.Net Registration Example Source Code

asp.net example

create login form in asp.net using database

In this asp.net tutorials we will learn to create dynamic login form in asp.net. There are two types of login forms programmer can create one is static login form and other is dynamic login form.

In static login form the username and password are fixed and predefined by programmer, and in dynamic login form the username and password match from database username and password and there are multiple user can login with this dynamic login form.

For create dynamic login form in asp.net first create database table for  username and password. we have here create a table “LoginMst” with three columns the ID, Username and Password.

The login form Example output is :

create login form in asp.net using database

create login form in asp.net using database

The Database table like :

create login form in asp.net using database

create login form in asp.net using database

In this asp.net login form example we first check if the username and password textbox are blank then show the error message like “Please enter username” for username textbox and for password the error message is “Please enter password” using required field validator control in asp.net. If the textbox are not empty  then match the username and password with database fields, if match then show the success message like “Welcome to System” , if do not match then shows the error message “Invalid username and password”.

Now, create a web application in visual studio and design a login web form.

The Design HTML code for login form :

After, design a web page write a server code on login button click events.

First add this namespace for connection.

using System.Data;
using System.Data.SqlClient;

C# .Net Code fro login button.

Download ASP.Net Login Example
asp.net example

Insert Update Delete data in Gridview asp.net using SQLDataadapter method

In previous asp.net post we have discussed about insert update and delete data in gridview using dataset and table  adapter method.

In this asp.net post we will learn insert edit update and delete data in gridview control in asp.net using SQLConnection and SQLDataAdapter method. we can do the same thing by using other connection method like LINQ connection and SQLCommand and stored procedure method.

For understand edit update delete gridview example, First we insert records in to database and select records from database and bind it to gridview control, then update and delete record in gridview using sql dataadater method.

 Step for Insert Edit Update Delete GridView asp.net example

Step 1 – Create database table and create new asp.net web application.

Step 2 – Design asp.net web page for gridview example.

Step 3 – Add name space for sql connection DataTable object. 

Step 4 – using System.Data.SqlClient; using System.Data;

Step 5 – AutoGenerateDeleteButton=”True” and AutoGenerateEditButton=”True”

Step 6 –Declare SQLConnction and SQLDataAdapter object for connectivity.

Step 7 – Insert record to gridview and update, delete records in gridview.

For understand this asp.net gridview example we need to create sql database table.

Here, we have created UserMst table for doing this example.

This is the script for create sql table.

Now, after creating sql table design asp.net web page for gridview example.

 HTML Source code for asp.net web page

 

Insert Update Delete data in gridview control in asp.net c#

Insert Update Delete data in gridview control in asp.net c#

Now, finishing design make connection between sql database and asp.net web application. In this asp.net gridview example we use sql connection and sql dataadapter method for connectivity. In this method we write sql  query in our code behind page instead of writing sql stored procedure.

Now, set gridview property shows like below.

AutoGenerateDeleteButton=”True”
AutoGenerateEditButton=”True”
DataKeyNames=”ID”

Insert Update Delete data in gridview control in asp.net c#

Insert Update Delete data in gridview control in asp.net c#

Enable Gridview events for Edit update delete records in gridview.

onrowcancelingedit=”GridView1_RowCancelingEdit”
onrowdeleting=”GridView1_RowDeleting”
onrowediting=”GridView1_RowEditing”
onrowupdating=”GridView1_RowUpdating”

Insert Update Delete data using Gridview in asp.net C#

First add namespace for sql connectivity.

Here is C# sample code for insert update delete record using gridview in asp.net

 

 Gridview Example Result :

Insert Update Delete data in gridview control in asp.net c#

Insert Update Delete data in gridview control in asp.net c#

Insert Update Delete data in gridview control in asp.net c#

Insert Update Delete data in gridview control in asp.net c#

 

Insert Update Delete GridView in ASP.Net C# VB

In this asp.net post we will learn, how to insert update and delete records in gridview using asp.net C# and VB language.

To understand this example we must make connection between mssql server database and asp.net web application. There are many method to make connection between sql server and asp.net application. This gridview example we are using dataset and stored procedure method for connectivity. Next asp.net example we will make connection using SqlConnection and SqlDataadapter method and SqlCommmand and Stored Procedure method and Linq method.

In this asp.net gridview example first insert data in to database and then select data and  recorbind to gridview. After bind data to gridview we will edit and update records in gridview and simple delete records from gridview by clicking delete button.

Step for Insert Update Delete GridView asp.net example

Step 1 – Create database table and create asp.net web application.

Step 2 – Create Sql Stored Procedure for Select, Insert, Update and Delete data.

Step 3 – Design asp.net web page for gridview example.

Step 4 – Add new DataSet for sql connectivity, Bind all stored procedure to dataset.

Step 5 – AutoGenerateDeleteButton=”True” and AutoGenerateEditButton=”True”

Step 6 – Insert record to gridview and update, delete records in gridview.

For understand this asp.net gridview example we need to create database table.

Here, we have created UserMst table for doing this example. This is the script for create sql table.

 

create new table in sql server databse.

create new table in sql server databse.

Now, design asp.net web page for insert update delete gridview example.

Here is HTML code for asp.net web page.

 

 

Insert Update Delete data  in gridview using asp.net c# and vb.

Insert Update Delete data in gridview using asp.net c# and vb.

After design asp.net web page for gridview example, now make connectivity between asp.net application and database table.

We are using DataSet and Stored Procedure method for connectivity.

Set Gridview Property

AutoGenerateDeleteButton=”True”
AutoGenerateEditButton=”True”
DataKeyNames=”ID”

 

Enable Gridview events for Edit update delete records inn gridview.

onrowcancelingedit=”GridView1_RowCancelingEdit”
onrowdeleting=”GridView1_RowDeleting”
onrowediting=”GridView1_RowEditing”
onrowupdating=”GridView1_RowUpdating”

Insert Update Delete Records in Gridview using asp.net C#

Here is the c# code for simple insert update and delete operation in gridview control in asp.net.

 

 

Insert Update Delete Records in Gridview using asp.net VB

 

 

Asp.net gridview Insert Update Delete example output is :

Insert Update Delete data  in gridview using asp.net c# and vb.

Insert Update Delete data in gridview using asp.net c# and vb.

Insert Update Delete data  in gridview using asp.net c# and vb.

Insert Update Delete data in gridview using asp.net c# and vb.

 

Country State City Cascading DropDownList with Database in ASP.Net

Cascading DropDownList Control with Database in ASP.Net C#.

In previous asp.net article, we have discussed about how to display cascading dropdownlist control without database in asp.net.

In this asp.net tutorial we will learn how to display cascading dropdownlist control using database in asp.net. For display values in dropdownlist control, first we need to insert data into database. Here, we use sql server database, first create a new database and create three table for County data, State Data and last one for City Date.

The Database table design should be like :

TableName = CountryMst
Columns :  CID (primary key / AutoIncrement) , CountyName as Nvarchar(200)

TableName = StateMst
Columns : SID (primary key / AutoIncrement), StateName as Nvarchar(200), CID as int

Table Name = CityMst
Columns : CID (primary key / AutoIncrement), CityName as Nvarchar(200), SID as int

Here is the screen short of sql server database table.

Table Design for CountryMst

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net C#

Table Design for StateMst

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net C#

Table Design for CityMst

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net C#

Here, below screen we can see the Database Example contains three table CountryMst, StateMst and CityMst with columns  and datatype in sql server.

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

Now, After Design Database table it’s time to create a stored procedure for manipulate database table.

Create New Stored procedure :

Database –> Example –> Programmability — > Stored Procedure

Here is code for all stored procedure we have created for our asp.net example.

Stored Procedure : COUNTRY_SELECT

 Stored Procedure : COUNTRY_INSERT

 Stored Procedure  : STATE_SELECT

  Stored Procedure  : STATE_INSERT

   Stored Procedure  : STATE_SELECT_BY_CID

 Stored Procedure  : CITY_SELECT

 Stored Procedure  : CITY_INSERT

Stored Procedure :  CITY_SELECT_BY_SID

 

Now, Create a new asp.net web application and design a web forms for inset data into sql server database.

First Design asp.net web page like below for insert country, state and city data.

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

The HTML Source code for above web page design is :

In this asp.net cascading dropdownlist example we use MultiView control for make user friendly design to easily understand. we took here three view control each for county, state and city inside the multiview control.

Now, first we have to insert country data then after state data and finally insert city data according to inserted data.

Here, the first output screen of insert data in to table for country, state and city.

Cascading dropdownlist in asp.net

Cascading dropdownlist in asp.net

In above screen there are three button control for display view control one by one as per button click.

First import three namespace on code behind page for sql connectivity.

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

Write a connection string code above page_load events :
Here, we have created a private function bindconnection for selecting data from database using SELECT Storedprocedure.

string strconn = “Data Source=.\\NEWSQLEXPRESS;Initial Catalog=’EXAMPLE’;Integrated Security=True”;
protected void Page_Load(object sender, EventArgs e)
{

}

private DataTable bindconnection(string queryname)
{

SqlConnection sqlconn = new SqlConnection(strconn);
SqlCommand sqlcmd = new SqlCommand(queryname, sqlconn);

SqlDataAdapter adapter = new SqlDataAdapter(sqlcmd);
DataTable DT = new DataTable();
adapter.Fill(DT);
return DT;
}

The asp.net c# code behind code for  ADDCounty Button control click event.

The C# Code for ADD State Button :

The C# Code for ADD City Button :

Now, when we select the add country button then the only view1 is displayed for insert country data in to CountryMst table in database.

Add New County Data in to CountyMst table in sql server :

Cascading dropdownlist in asp.net

Add New County Data in to CountryMst Table

The C# code for ADD button to insert new country records.

Now, After adding some country records insert new state record respectively to country records.

Cascading dropdownlist in asp.net

Add New State Data in to StateMst Table

The C# code for ADD State records :

Now, Add new city records as per the selected country and state record.

Cascading dropdownlist in asp.net

Add New City Data in to CityMst Table

Cascading dropdownlist in asp.net

Add New City Data in to CityMst Table

Here, when we select country from county dropdownlist then the related state will be displayed automatically in state dropdownlist control. for do this write a code behind c# code on Country Dropdownlist SelectedIndexChanged and set AutoPostBack = True

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

The code for County Dropdownlist SelectedIndexChnaged events :

The C# Code for Add new City Records :

Now, up to this we have successfully added country, state and city records in database.

Let’s take an example to understand cascading dropdownlist from database. In above example we have insert records in to databse for country, state and city. Now desing an asp.net web page for cascading dropdownlist for country, state and city. In cascading drodownlist example we display records respectively from database, which we alreay inserted in above example.

First Design asp.net web page for cascading dropdownlist example.

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

The HTML Source code for cascading dropdownlist example is :

For display state recordes according to select country records and display city records according to select country and state record, we need to set AutoPostBack = true for Country and State Dropdownlist control.

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

Import  namespace and write connection string code like :

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

string strconn = “Data Source=.\\NEWSQLEXPRESS;Initial Catalog=’EXAMPLE’;Integrated Security=True”;
protected void Page_Load(object sender, EventArgs e)
{

}

write below code in page_load events for bind country dropdownlist control from databse.

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

The C# code for County Dropdownlist SelectedIndexChanged events :

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

The C# code for State Dropdownlist SelectedIndexChanged events :

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

Country State City DropDownList in ASP.Net

I hope this asp.net country, state and city cascading dropdownlist from database example will help you…..

Country, State and City DropDownList Example in ASP.Net C#

County, State and City cascading dropdownlist control example

The dropdownlist control is used to store multiple items in asp.net. The country, state and city dropdownlist example means, we have three dropdownlist control one for each country, state and city.

The first dropdownlist is for country, if we select country from dropdownliste then related state name automatically displayed in second dropdownlist. If we select any state from state dropdownlist then the city which is related to selected state will be displayed in third city dropdownlist control.

This type of dropdownlist example we can say cascading dropdownlist.

Let’s understand cascading dropdownlist example with country, state and city.

First create a web application in asp.net with default.aspx web page.

Now design asp.net web page with three dropdownlist control with two button control shows like below screen.

Here is the html source code for asp.net default.aspx page.

Here is the layout of asp.net web page for cascading dropdownlist example.

Here, we have taken three dropdownlist control one for country, second for state and third for city.

In the county dropdownlist insert manually county name and select county name and click select button to display related sate name in second dropdownlist.

Cascading dropdownlist

Cascading dropdownlist control for country, state and city in asp.net C#

Here is the code for two button control click events.

The Country Button Code :

The State Button Code :

Cascading dropdownlist

Cascading dropdownlist control for country, state and city in asp.net C#

Below asp.net figure shows we have select country INDIA and state Gujarat then related city will be automatically displayed in third city dropdownlist control.

Cascading dropdownlist

Cascading dropdownlist control for country, state and city in asp.net C#

We have make proper validation for selection, if you don’t select any county from country dropdownlist then you will get error message like Select Proper County !!.

Cascading dropdownlist

Cascading dropdownlist control for country, state and city in asp.net C#

If we don’t select proper state then the error message look like Select Proper State!!.

Cascading dropdownlist

Cascading dropdownlist control for country, state and city in asp.net C#

Cascading Dropdownlist Example using AutoPostBack

In above example we have taken two button control for select country and select state. Now we have make same cascading example without taking button control.

The AutoPostBack Property of DropDownlList control

The Autopostback property of dropdownlist control allow user to execute code behind code while changing selected item from dropdownlist control in asp.net. If we use autopostback then in above example we don’t need to use button control for server code.

we can write server code on SelectedIndexChanged events of dropdownlist control.

we take above same cascading dropdown example using autopostback in asp.net.

Here we took only three dropdownlist control for country, state and city. we write server side code on dropdownlist SelectedIndexChanged events instead of button click events.

Cascading dropdownlist

Cascading dropdownlist using autopostback for country, state and city in asp.net C#

Now, after designing asp.net web page, set AutoPostBack = true for country and state dropdownlist control.

Cascading dropdownlist

Cascading dropdownlist using autopostback for country, state and city in asp.net C#

Now go to the SelectedIndexChanged events of country dropdownlist for write server code.

Code for country SelectedIndexChanged events :

Code for State SelectedIndexChanged events:

 

Cascading dropdownlist

Cascading dropdownlist using autopostback for country, state and city in asp.net C#

 

Cascading dropdownlist

Cascading dropdownlist using autopostback for country, state and city in asp.net C#

 

 

TextBox Remaining Character Counter using JavaScript in ASP.Net

In this asp.net post i will show you how to count the remaining character in textbox control using javaScript in asp.net.

First design asp.net web forms with one textbox control and a Label Control.

Here, we can see the remaining character while we write text in textbox control, we use javaScript for count the remaining character.

Here, we call the javascript function on onkeyup textbox events.

First set the textbox MaxLength=15 and call javascript function on onkeyup=”cnt()”.

below is the design of asp.net web forms:

 

Here is the JavaScript function for count remaining character:

The output of count remaining character in textbox using javascript :

TextBox Remaining Character Counter using JavaScript in ASP.Net

TextBox Remaining Character Counter using JavaScript in ASP.Net

– above screen shows the total length of textbox is 15. when we write text into textbox the count automatically decreases according to length of textbox text.

TextBox Remaining Character Counter using JavaScript in ASP.Net

TextBox Remaining Character Counter using JavaScript in ASP.Net

– in above forms we write “meera” the 5 character then the count shows the 10 character is remaining in textbox control.

TextBox Remaining Character Counter using JavaScript in ASP.Net

TextBox Remaining Character Counter using JavaScript in ASP.Net

Validate DropDownlList Control unsing RequiredField Validator in ASP.Net

In this asp.net post we will learn how to validate dropdownlist control using requiredfield validator control in asp.net.

For understand validate dropdownllist control in asp.net using required field control create a asp.net web for with one dropdownlist control, button control along with requiredfield control.

take dropdownlist control and add some items in dropdownlist, In dropdownlist control we must select item from second to last, means requiredfiled validator control show the error message, if we select the first item from dropdownlist.

Here is the design code for dropdownlist example:

– design code for requiredfiled validator control:

here, we set two property of requiredfield validator
– ControlToValidator=”DropDownList1″
-InitialValue=”SELECT” <– Fist value of dropdownlist control

Here, is the output of dropdownlist control validate asp.net example:

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

Validate Dropdownlist control using RequiredField Validator control in ASP.Net

How to use string Length() in C#

Length()  – The string Length method used to calculate the character length of string.

Length method returns the integer value in result.

 

How to use Length() string method in C#

How to use Length() string method in C#

 

write c# code on button click events :

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = “Length = ” +TextBox1.Text.Length.ToString();
}

 

How to use Length() string method in C#

How to use Length() string method in C#

 

How to use Length() string method in C#

How to use Length() string method in C#

How to use string StartsWith() and EntsWith() in C#

StratsWith() – StartsWith() string method check if the parameter string startswith specified string.

EndsWith() – EndsWith() string method check if the parameter string endswith specified string.

How to use StratsWith() and EndsWith() string method in C#

How to use StratsWith() and EndsWith() string method in C#

 

write below code on Stratswith button click events:

protected void Button1_Click(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;

Label1.Text = str1.StartsWith(str2).ToString();
}

How to use StratsWith() and EndsWith() string method in C#

How to use StratsWith() and EndsWith() string method in C#

 

write below code on Endswith button click events:

protected void Button2_Click(object sender, EventArgs e)
{
string str1 = TextBox1.Text;
string str2 = TextBox2.Text;

Label1.Text = str1.EndsWith(str2).ToString();
}

How to use StratsWith() and EndsWith() string method in C#

How to use StratsWith() and EndsWith() string method in C#

 

How to use StratsWith() and EndsWith() string method in C#

How to use StratsWith() and EndsWith() string method in C#

string ToUpper() and ToLower() in C#

ToUpper() – ToUpper() string method in c# used to convert string alphabets values to Uppercase alphabets values.

ToLower() – ToLower() string method in c# used to convert string alphabets values to Lowercase alphabets values.

Here, we understand ToUpper() and Tolower() method with an example.

How to use ToUpper() and ToLower() string method in C#

How to use ToUpper() and ToLower() string method in C#

write below code on ToUpper() Button control click events:

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text.ToUpper();

}

code for ToLower() button control:

 protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text.ToLower();
}

 

When we click the button ToUpper, all the values of textbox will be converted to Uppercase, shows like below screen.

How to use ToUpper() and ToLower() string method in C#

How to use ToUpper() and ToLower() string method in C#

 

How to use ToUpper() and ToLower() string method in C#

How to use ToUpper() and ToLower() string method in C#