16 February 2014

How to use Query String in ASP.NET Application?

Query string is a method that store the state information on the client end.If we want to send some information from the previous page to the Next page then we can send the information as the Bar of URL by specifying '?' symbol within URL after the '?' mark.
whatever URL specify is consider as Query string.
Query string is not secure because their values are exposed to the Internet through the URL .

There are some steps to understand the whole concept of Query string.which are given below:-
Step 1:-

 First open your visual studio-->File--> New-->website -->select ASP.NET  Empty website -->OK-->Open Solution Explorer --> Add two web forms -->Drag and Drop Label,Button and Text Box on first web form as shown below:-

home page

Step 2:- Now Double Click on 'Submit' button--> write the following codes as given below:-
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Query_string : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
 Response.Redirect("default.aspx?id="+TextBox1.Text+"&Mobile="+TextBox2.Text+"");
        }
    }
}

Step 3:- Now Drag and Drop two label control on second web form as shown below:-


information

Step 4:- Now Double click on second web form and write the following codes on page load as given below:-

?
1
2
3
4
5
6
7
8
9
10
11
12
13
using System;
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)
    {
        Label1.Text = Request.QueryString["id"];
        Label2.Text = Request.QueryString["Mobile"];
    }
}

Step 5:- Now Run Application (press F5)-->and enter the required fields as shown below:-


details

Step 6:- Now press the Submit Button,You will see that first page information(User Name and Mobile Number) send to second page through the URL  as show below:-


store data

Explaining about Web Forms Controls in ASP.NET(I)?

Asp.net is Fully Based on Controls.Before Making any application ,I will learn First  about the Asp.Net Controls.If you will understand the Use of Controls then you can easily make any Application without any problem in Asp.Net.There are some Types of controls which are used in Asp.Net.

  • Web Forms Standard controls.
  • Navigation Controls
  • Validation Controls
  • Web Parts controls
  • Html Controls
we will understand one by one each Controls with Real Application.Now I am going to Know  What is Web Forms Controls In Asp.Net?.
Note:- Whenever you will use Web Forms Controls  in your Application then First write one Namespace Which is Given below:
using System.Web.UI.WebControls;
Because All Web Forms Controls comes Under this Namespace .
Web Forms Controls:-
There are some Web Forms Controls which is given below with Real Time Example:-
  1. Label Control
  2. TextBox control
  3. Button control
  4. Literal control
  5. PlaceHolder control
  6. HiddenField control
  7. FileUpload control
  8. Image control
  9. ImageButton control
  10. ImageMap control

     1.) LABEL CONTROL:-

The Label Control is basically used to display the Information(Text) on Web Forms.Any end User can not Edit(change) the Label Information.
Properties of Label Control:-
There are some important properties of Label controls.
  • Text:-It is used to change the Label control information(text).
  • Font:- It is used to sets the font of the Label text.
  • ForeColor:- It is used to sets the text color in the Label.
  • Height:- It is used to Specify the height of the Label Control.
  • BackColor :-It is used to Sets the Background color of the Label control.
  • BorderWidth:-It is used to Sets the Border color of the Label control.
  • BorderStyle:-It is used to Sets the Style of the Label control.
  • AccessKey:-It is used to Navigate the Web Server control.
There are some steps to implement the Label control on  the Web Form which is given below:
Step :1 First Open Your Visual Studio-->File-->New-->Web Site-->Select ASP.NET Empty Web Site-->OK-->Open Solution Explorer-->Right Click on Web Site-->Add New Item -->Select Web Form--> click Add-->Now drag and drop Label and Button control  from Toolbox on  the Web Form as Given below:

Step :2 Now Double Click on Click Button and Write the following codes which is shown below:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class labelcontrol : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label2.Text = "You can easily display any information inside it";
    }
}

Step :3 Now Run The Program(Press F5) and Press the Click Button.
Output:



     2.) TEXTBOX CONTROL:-

The TextBox control is used to input the Data(text).Any end user can easily enter the text in this control.
Properties of TextBox Control:-
There are some important properties of TextBox controls.
  • Text:-It is used to sets the text in TextBox Control.
  • TextMode:- It is used to sets the mode of the TextBox Control as Single Mode,Multiline or Password.
  • Rows:-It is used to sets the number of rows display in a TextBox(Multiline).
  • MaxLength:->It is used to sets the maximum number of character alloweded in a TextBox control.
  • ReadOnly:-It is used to read the contents by the end used but can not change it.
  • Columns:-It is used to sets the width of character in TextBox.
  • AutoCompleteType:-It is used to sets a value that indicates the Auto Complete behavior of the TextBox control.
  • AutoPostBack:-It is used to handle the event when the TextBox control lose focus.
  • CauseValidation:-It is used to set a value that validate the TextBox control(client,server).
  • TextChange:-It is an event.It occurs when the end user change the text of the TextBox control.

15 February 2014

Explanining about Web Forms Controls in ASP.NET(II)?

All Asp.Net Controls are very useful for Making a Real Time Application in .NET.Now i am going to explain important web forms controls in ASP.NET with a real application.
There are some controls :-
The ListBox control
The DropDownList control
The BulletedList control
The Hyperlink control
The Link Button control
The checkBox control
The checkBoxList control
The RadioButton Control
The RadioButtonList control
The calendar control
The AdRotator control

Note:- All the above web Forms controls resides within the following Namespace which is given below:-
 using System.Web.UI.WebControls;
1.) THE LISTBOX CONTROL:-
                                               The ListBox control is a web server control,which is used to select one or more items from a list of items on a web page at Runtime in ASP.NET.

There are some important properties of the List Box Control.
Property                              Description

BorderWidth               It is used to set the border width of the control
Bordercolor                It is used to set the border color of the control
SelectionMode            It is used to set the Selection mode of the control
Rows                         It is used to set the Number of Rows display in the control
BorderStyle                It is used to set the Border style of the control.

There are some steps to implement this control please follow it.
Step: 1:
Open your visual studio-->File -->New-->Website-->ASP.NET Empty website-->OK-->Open your Solution Explorer-->add New Web form-->Drag and Drop Label,Button and ListBox control on web form from Toolbox as shown below:

Step: 2 Now Add Database.mdf in your website-->Create table (student) and columns.For More Details..


Step: 3
Now click on ListBox -->choose Data Source -->Select a New Data Source-->Select Database -->OK-->choose Database.mdf and proceed with Next Button as Shown below:

Select Database:-


    Proceed Next:-
                                       


Step: 5 Double click on Submit Button and Write the following codes.Which is given below:

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ListBox : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label2.Text = "Hello " + ListBox1.SelectedItem.Text;
    }
}


Step: 6 Now Run the Program (Press F5).

2.) THE DROPDOWNLIST CONTROL:-

It is used to display the List of data from which you make single selection.This control comes under  using System.Web.UI.WebControls Namespace.The DropDownList Control inherits the List Control Class.
There are some important properties of the DropDownList control.
Some properties are same as List Box Control Properties:-
BorderWidth
Bordercolor
BorderStyle
SelectedIndex
There are some steps to implement this control please follow it.
Step: 1
Add a New web form in your Solution Explorer-->Drag and Drop Label,Button and DropDownList control on the Form as shown below:


Step: 2
Now Configure the Data source as I have  configured  above in the ListBox control.
                             
Step: 3
Now Double click on Submit Button and write the following codes.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Dropdownlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label2.Text = "Hello  " + DropDownList1.SelectedItem.Text;
    }
}

Step: 4 Now Run the Program (Press F5).
Output:
                                 
3.) THE BULLETEDLIST CONTROL:-

It is a web server control which is used to display the items in the Form of a Bulleted List on the web Page.
There are some Important properties of the BulletedList Control :-
Text :-It is used to set the text of the BulletedList control.
AutoPostBack:-It is used to set the value of the AutoPostBack Property of the control.
SelectedIndex:-It is used to set the currently selected item in a BulletedList control.
SelectedItem:-It is used to set the currently selected item in a BulletedList control.
SelectedValue:- It is used to set the value property of the selected List Item object of the control.
DisplayMode:-It is used to set the DisplayMode  of the List items appearing in the control.
BulletedImageUrl :-It is used to set the Path to an image to display for each Bullet in the control.
FirstBulletedNumber:- It is used to set the value that starts the numbering of the list in the control.
Target:-It is used to set the target value when any user click the BulletedList control values.

There are some steps to implement this control please follow it.

Step: 1
Drag and Drop BulletedList control from the toolbox-->Go Properties-->Items-->Add values as shown below:


Step: 2 Now Run the Program(Press F5)
Output:

How to Add a Captcha Image in ASP.NET Application?

Hai ! There are some steps to Add Captcha image in Asp.NET Application.You can easily add this captcha image to your Asp.Net Application Without any Problem.
Please follow these  steps one by one which are given below.

Step1:-
First create ASP.NET page (Default.aspx) in visual studio 2010--> Now download the captcha.dll file from Microsoft Site.

see captcha.dll file:-


Step2:-
Now Open Solution Explorer -->Add new Folder(Bin)->open the captcha.dll file->copy all the file -> Now paste it in the Bin Folder.
see it:-

Step3:- Now Write the code for captcha control in Source file as shown below:
see it:-

Step4:-  Now Drag and Drop Text-box,Button, Label and Validation controls on Default.aspx page from the Toolbox.which is as shown below:-
see it:-
                             

Step5:- Now Double click on Button control(Verify) and write the following code.

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)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        captcha1.ValidateCaptcha(TextBox2.Text.Trim());
        if (captcha1.UserValidated)
        {
          Label1.ForeColor = System.Drawing.Color.Green;
          Label1.Text = "You have Entered Valid Captcha Characters";
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "You have Entered InValid Captcha Characters please Enter again";
        }
    }
}
see it:-

Step6:- Now open the web.config file and write the following codes as shown below.
                       
Step7:- Run the Application (press F5).
          OUTPUT:-
when we Enter the  correct captcha image In the  Text-Box and click Verify Button,then we see following output:-                  
   
when we Enter the  In-correct captcha image In the  Text-Box and click Verify Button,then we see following output:-
                         


How to Add SQL Database (.mdf) in ASP.NET Website

Hai ! Now Give information about how to Add .mdf Database in ASP.NET Application.

There are some steps to Add SQL Database (.mdf) in ASP.NET Website. Which are given below:
Step1:-
First open your visual studio 2010-> go File-> click New Website->Select ASP.NET Empty website->click OK.
Go Solution Explorer->Add New web form(Default.aspx)-->Drag and drop some controls as shown below :-
see it:-

Step2:- Now open Solution Explorer-> Right mouse click on website(Application) which is as  shown below:-
See it:-

Now Select SQL Server Database->click Add button ,which is shown below:-
see it:-

Step3:-  Now Double click on Database.mdf File in Solution Explorer->Now  Right click on Tables  Click Add New Table->Now Write required column Name-> Click save  button ->Write the table NAME-> Click OK. which is  as shown below :-
see it:-


Step4:-  Now Double click on Submit Button -> Write the following code for Database connectivity which are given below:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(@"Data Source=SHIVACHARAN-PC;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True;");

    con.Open();
    String str = "INSERT INTO login (username,password) VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "')";
    SqlCommand cmd = new SqlCommand(str, con);
    int OBJ = Convert.ToInt32(cmd.ExecuteNonQuery());
    if (OBJ > 0)
    {
        Label3.Text = "Data is successfully inserted in database";
    }
    else
    {
        Label3.Text = "Data is not inserted in database";
    }
    con.Close();

    }
}
see it:-
Step5:-  Run the Application(Press F5).Which are shown below:
Output:-
Step6:- Now you can see the inserted data in Database.
see it:-