Tuesday 27 September 2011

C# change password code with asp.net using ado.net and sql server?

Here the code of  Password change:-

public partial class Change_Password : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=abc;Initial Catalog=database name;
Integrated Security=True");
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{

}

Showing & hiding div layers on button clicks

Here is the code:-

<html>
<head>
<title>(Type a title for your page here)</title>
<style type="text/css">
div {
position: absolute;
left: 100px;
top: 200px;
background-color: #f1f1f1;
width: 180px;
padding: 10px;
color: black;
border: #0000cc 2px dashed;
display: none;
}
</style>

Monday 26 September 2011

Automatic images will be changes through Javascript


 Images will automatically changes it's really amazing:-

<script type="text/javascript">

       // Set the slideshow speed (in milliseconds)
       var SlideShowSpeed = 5000;

       // Set the duration of crossfade (in seconds)

       var CrossFadeDuration = 2;
       var Picture = new Array(); // don't change this

Insert, Update,Edit,Cancel and Delete in Gridview

Code of Delete:-
1. Make the Procedure 

ALTER procedure [dbo].[delete1]
@id int
as
begin
delete from registration where id=@id;
end

Simple Code Of Registration

Step 1. Make Table
Step 2. Make Store Procedure like this:-

ALTER procedure [dbo].[regis]
@name nvarchar(34),
@email nvarchar(45),
@password nvarchar(34),
@verify_password nvarchar(34),
@address nvarchar(78),
@phone nvarchar(23),
@state nvarchar(34),
@country nvarchar(23)
as
begin
insert into registration values(@name,@email,@password,@verify_password,@address,@phone,@state,@country);
end

Step 3. Take a Class library and write this code:-

public class connection
{
public bool save_data(string fname, string email, string password1, string verify_password, string address, string phone, string state, string country)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ToString());
        SqlCommand cmd = new SqlCommand("regis", con);
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@name", fname);
        cmd.Parameters.AddWithValue("@email", email);
        cmd.Parameters.AddWithValue("@password",FormsAuthentication.HashPasswordForStoringInConfigFile ( password1,"Md5"));
        cmd.Parameters.AddWithValue("@verify_password",verify_password);
        cmd.Parameters.AddWithValue("@address", address);
        cmd.Parameters.AddWithValue("@phone", phone);
        cmd.Parameters.AddWithValue("@state", state);
        cmd.Parameters.AddWithValue("@country", country);
        con.Open();
        int i = cmd.ExecuteNonQuery();
        con.Close();
        if (i > 0)
            return true;
        return false;

    }
}

Step 4. Call this function on Registration button like this:-

protected void Registration_Click(object sender, EventArgs e)
    {
        connection ur = new connection();
        bool check = ur.save_data(Tname.Text.Trim(),Temail.Text.Trim(),Tpassword.Text.Trim(),Tverifypassword.Text.Trim(),
Taddress.Text.Trim(),Tphone.Text.Trim(),Tstate.Text.Trim(),Dcountry.SelectedItem.Text );
        if (check == true)
        {
            Response.Write("Congrachulations! you have succesfully registered");
        }
        else
        {
            Response.Write("Please fill information correctly");
        }
    }

Simple Code of Login Page Through Store Procedure

Login Code:-

 protected void Login_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["con"].ToString());
        string sqlquery = "select count(*) from registration where email=@email and password=@password";
        SqlCommand cmd = new SqlCommand(sqlquery, con);
        cmd.Parameters.AddWithValue("@email", Tlogin.Text);
        cmd.Parameters.AddWithValue("@password", FormsAuthentication.HashPasswordForStoringInConfigFile(Tpassword.Text, "Md5"));



        con.Open();
        int i = (int)cmd.ExecuteScalar();
        if (i > 0)
        {
            Response.Write("Congrachulations! U successfully enter in profile");
        }
        else
        {
            Response.Write("Please check username or password");
        }
        con.Close();
    }


Saturday 24 September 2011

What is Detalview, Formview,Gridview,Repeater and Datalist in Asp.net

GridView Control:
The GridView control displays data as a table and provides the capability to sort columns, page through data, and edit or delete a single record. the GridView control offers improvements such as the ability to define multiple primary key fields, improved user interface customization using bound fields and templates, and a new model for handling or canceling events

DetailsView Control:
The DetailsView control renders a single record at a time as a table and provides the capability to page through multiple records, as well as to insert, update, and delete records. The DetailsView control is often used in master-detail scenarios where the selected record in a master control such as a GridView control determines the record displayed by the DetailsView control.

FormView Control:
The FormView control renders a single record at a time from a data source and provides the capability to page through multiple records, as well as to insert, update, and delete records, similar to the DetailsView control. However, the difference between the FormView and the DetailsView controls is that the DetailsView control uses a table-based layout where each field of the data record is displayed as a row in the control. In contrast, the FormView control does not specify a pre-defined layout for displaying a record. Instead, you create templates that contain controls to display individual fields from the record. The template contains the formatting, controls, and binding expressions used to lay out the form.

Repeater Control:
The Repeater control renders a read-only list from a set of records returned from a data source. Like the FormView control, the Repeater control does not specify a built-in layout. Instead you create the layout for the Repeater control using templates.

DataList Control:
The DataList control renders data as table and enables you to display data records in different layouts, such as ordering them in columns or rows. You can configure the DataList control to enable users to edit or delete a record in the table. The DataList control differs from the Repeater control in that the DataList control explicitly places items in an HTML table, where as the Repeater control does not.

Difference between Datagrid,DataList and Data Repeater:
  • Datagrid has paging while Datalist doesnt.
  • Datalist has a property called repeat. Direction = vertical/horizontal. (This is of great help in designing layouts). This is not there in Datagrid.
  • A repeater is used when more intimate control over html generation is required.
  • When only checkboxes/radiobuttons are repeatedly served then a checkboxlist or radiobuttonlist are used as they involve fewer overheads than a Datagrid.

Friday 23 September 2011

Highlight row in gridview on mouseover using css and Javascript in Asp.Net.

Step 1 : Drag and Drop GridView from Visual Studio toolbox to your asp.net web page
Step 2: In your HTML view of webpage inside the head tag or if you have .css file in your project you can write these lines of css code 

<font color="#0000ff" size="2"><font color="#0000ff" size="2"><style type="text/css">



.normalRow
{
background-color:white;/* You can update the background Color to normal Gridview Back Color */
cursor:pointer;/* You can change cursor pointer to default, Pointer etc */
}
 
.highlightRow
{
background-color:Gray;/* You can change the background Color of the row to whatever color you want. You can also give Hexadecimal color code also */
cursor:pointer;/* You can change cursor pointer to default, Pointer etc */
}
 
</style>
</font></font>                                                          
 Step 3: On RowCreated event of Gridview which will fire when you can Bind() Method of Gridview for eg GridView1.DataBind(); write this code

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
// Leave header and footer of Gridview and assign in the rest of the item row
if (e.Row.RowType != DataControlRowType.Header || e.Row.RowType != DataControlRowType.Header)
{
e.Row.Attributes.Add("onmouseout", "this.className='normalRow'");
e.Row.Attributes.Add("onmouseover", "this.className='highlightRow'");
}
}

Thursday 22 September 2011

Complete Navigation Bar (x)HTML And CSS


The complete code for our simple navigation bar is:

<ul id="list-nav">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Products</a></li>
<li><a href="#">Contact</a></li>
</ul>
ul#list-nav {
list-style:none;
margin:20px;
padding:0;
width:525px
}
ul#list-nav li {
display:inline
}
ul#list-nav li a {
text-decoration:none;
padding:5px 0;
width:100px;
background:#485e49;
color:#eee;
float:left;
text-align:center;
border-left:1px solid #fff;
}
ul#list-nav li a:hover {
background:#a2b3a1;
color:#000
}

Creating an attractive Hover Menu using CSS & JavaScript


 CSS hover menu

Below is a 100% CSS based hover menu. The source code for it follows.
<style type="text/css">

#coolmenu{
border: 1px solid black;
width: 170px;
background-color: #E6E6E6;
}

How to Create a Horizontal Menu through CSS?


In the following part of our CSS menu tutorial we will provide a sample code of a horizontal menu, which formating and functionality is defined using CSS:

<html>
<head>
<title>My horizontal menu</title>
<!--HTML head including the title tag-->
</head>
<body>
<!--HTML body including CSS and the HTML code.-->
<!--The beginning of the CSS code section. -->
<style type="text/css" media="screen">
/* Defines the unordered list attributes:  the list marker is removed, the space between the element border and the element content is set to 0 using the padding property and the space around the elements is also 0. */
#horizontalmenu ul {
padding:0; margin:0; list-style:none;
}
/* Defines the list items' attributes:  the items will float to the left, their position will be relative to the normal one; the space between the element's right border and the element content is set to 20 using the padding property; the items are displayed in a block with a 3D inset border. */
#horizontalmenu li {
float:left; position:relative; padding-right:20; display:block;
border:3px solid #000000; 
border-style:inset;
}
/* Hides the list items of the unordered list. */
#horizontalmenu li ul {
    display:none;
position:absolute;
}
/* When the mouse pointer hovers over the menu elements, the child unordered list items are shown in blocks; the width is set in em units. */
#horizontalmenu li:hover ul{
    display:block;
    background:none;
height:auto; width:8em; 
}
/* No floating elements allowed on either the left or the right side of the elements. */
#horizontalmenu li ul li{
    clear:both;
border-style:none;}
/* the end of the CSS code section; */
</style>
<!--The HTML part of the body section; Here the menu items are entered; They are visualized per the above CSS code definitions; in the div container we specify the unique id, which will be used.-->
<div id="horizontalmenu">
<ul>
  <li><a href="http://siteground.com/">Home</a></li>
  <li><a href="http://www.siteground.com/tutorials/">Tutorials</a>
    <ul>
      <li><a href="http://www.siteground.com/tutorials/cssbasics/index.htm">CSS</a></li>
      <li><a href="http://www.siteground.com/tutorials/flash/index.htm">Flash</a></li>
    </ul>
  </li>
  <li><a href="#">More</a>
    <ul>
      <li><a href="http://www.siteground.com/about_us.htm">About Us</a></li>
      <li><a href="http://www.siteground.com/contact_us.htm">Contact Us</a></li>
    </ul>
  </li>
</ul>
</div>
<!--The end of the body section and the html file.-->
</body>
</html> 
Please note that the above code is tested on the latest version of Mozilla Firefox. It should work normally on all new browsers, which support the hover functionality.

How to Create a Vertical Menu through CSS?


Here we will provide a sample code of a vertical menu, which formating and functionality is defined using CSS:
<html>
<head>
<title>My vertical menu</title>
<!--HTML head including the title tag.-->
</head>
<body>
<!--HTML body including CSS and the HTML code.-->
<!--The beginning of the CSS code section.-->
<style type="text/css" media="screen">
/* Defines the menu attributes: the background color, the menu displayed as a block, the block black border, the line height and the menu width -> 10% of the whole screen width. */

How To Validict Textbox Through Javascript

Firstly make the function in Javascript to validate Textbox:-

/*We can write this code under <script src="JScript.js" type="text/javascript">
function check_blank(fldid, msgid) {
    var fld = document.getElementById(fldid);
    if (fld.value.length == 0 || fld.value.charAt(0) == " ") {
        document.getElementById(msgid).innerHTML = "Require field has not been filled";
        return false;
    }
    document.getElementById(msgid).innerHTML = "&nbsp";
    return true;
}
 </script>

Call this function on Aspx page:-
Like if u want to validate Textbox  then simple call upper code on aspx page like as:-

  <asp:TextBox ID="Tname" onblur="return check_blank(this.getAttribute('id'),'fname')" runat="server" Height="32px" Width="285px"></asp:TextBox>
<td><span id="fname" style=" font-size:x-small;color:red;"></span></td>

Wednesday 21 September 2011

Getting number of active sessions (online users counter) with ASP.NET

All that have to be done is in global.asax file:
 Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Application["OnlineUsers"] = 0
End Sub

Tuesday 20 September 2011

Automatically images changes through javascript

 <!-- STEP ONE: Put this code into the HEAD of your HTML document  -->
 <head>
<script language="JavaScript">
function movepic(img_name,img_src) {
document[img_name].src=img_src;
}

</script>
</head>


Monday 19 September 2011

Interview Questions Of Asp.Net

ASP.NET 3.5 Interview Questions & Answers :



1. Explain the life cycle of an ASP .NET page.?
Following are the events occur during ASP.NET Page Life Cycle:

1)Page_PreInit
2)Page_Init
3)Page_InitComplete
4)Page_PreLoad
5)Page_Load
6)Control Events
7)Page_LoadComplete
8)Page_PreRender
9)SaveViewState
10)Page_Render
11)Page_Unload