Saturday, 8 June 2013

Wait for Downloading Or Click Here To Download Counter in JavaScript.

Demo:-  

About:- In Previous Article I Write About How to Highlight Searched Text In Gridview . In this Article using JavaScript  Learn How to create time wait Counter for downloading anything.

Coding:-

<html>
<head>
<title>Counter Example</title>

<script type="text/javascript" language="javascript">
function startcounter(s)
{
var de = document.getElementById("dCounter");
de.innerHTML = 'Please Wait For<br>' +  s  + '<br>Seconds';
if(s == 0)
{
document.getElementById("dAd").style.display = 'none';
document.getElementById("dDownload").style.display = 'block';
}
else
{
s--;
setTimeout('startcounter(' + s + ')',500);
}
}
function hidedcounter()
{
document.getElementById("dCounter").style.display = 'none';
}
</script>
</head>
<body onload="startcounter(10)">
<center>
<div id="dCounter" style="font:bold 30px verdana;"></div>
<br><br>
<div id="dAd">
<img src="hydrangeas.jpg" width="300" height="300" border="1" alt="Advertisement"/>
<br><br>
Or <br><a href="#" onclick="startcounter(0),hidedcounter()">Click Here</a>
</div>
<div id="dDownload" style="display:none;">
<input type="button" value="Download"/>
</div>
</center>
</body>
</html>

Tuesday, 4 June 2013

Hightlight Searched Text In Gridview Using Asp.net

Demo:-


Instruction:- To Execute this code Firstly Create the table using these fields below



And add the data to the Table.

Design 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 id="Head1" runat="server">
<title>Highlight the Search Keywords in Gridview </title>
<style type="text/css">
.GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;}
Table.Gridview{border:solid 1px #df5015;}
.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em 0.5em 0.5em 0.5em;text-align:center}
.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em 0.5em;}
.Gridview tr{color: Black; background-color: White; text-align:left}
:link,:visited { color: #DF4F13; text-decoration:none }
.highlight {text-decoration: none;color:black;background:yellow;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="GridviewDiv">
<p>
Author Name:
<asp:TextBox ID="txtSearch" runat="server" />&nbsp;&nbsp;
<asp:ImageButton ID="btnSearch" ImageUrl="~/SearchButton.png" runat="server"
Style="top: 5px; position: relative" onclick="btnSearch_Click" />&nbsp;&nbsp;
<asp:ImageButton ID="btnClear" ImageUrl="~/Clearbutton.png" runat="server" Style="top: 5px;
position: relative" onclick="btnClear_Click" /><br />
<br />
</p>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False" AllowPaging="True"
AllowSorting="true" DataSourceID="dsDetails" Width="540px" PageSize="10" CssClass="Gridview" >
<HeaderStyle BackColor="SkyBlue" />
<Columns>
<asp:TemplateField HeaderText="Author">
<ItemTemplate>
<asp:Label ID="lblAuthor" Text='<%# HighlightText(Eval("Author").ToString()) %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Category">
<ItemTemplate>
<asp:Label ID="lblCategory" Text='<%# Eval("Category") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Country">
<ItemTemplate>
<asp:Label ID="lblCountry" Text='<%#Eval("Country") %>' runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:SqlDataSource ID="dsDetails" runat="server" ConnectionString="<%$ConnectionStrings:dbconnection %>" SelectCommand="select * from TableU" FilterExpression="Author LIKE '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="Author" ControlID="txtSearch" PropertyName="Text" />
</FilterParameters>
</asp:SqlDataSource>
</form>
</body>
</html>

CodeBehind:- 

using System;
using System.Text.RegularExpressions;
using System.Web.UI;

public partial class _Default : System.Web.UI.Page
{
//  Create a String to store our search results
private string SearchString = "";
protected void Page_Load(object sender, EventArgs e)
{
}
public string HighlightText(string InputTxt)
{
string Search_Str = txtSearch.Text;
// Setup the regular expression and add the Or operator.
Regex RegExp = new Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase);
// Highlight keywords by calling the
//delegate each time a keyword is found.
return RegExp.Replace(InputTxt, new MatchEvaluator(ReplaceKeyWords));
}
public string ReplaceKeyWords(Match m)
{
return ("<span class=highlight>" + m.Value + "</span>");
}
protected void btnSearch_Click(object sender, ImageClickEventArgs e)
{
//  Set the value of the SearchString so it gets
SearchString = txtSearch.Text;
}
protected void btnClear_Click(object sender, ImageClickEventArgs e)
{
//  Simple clean up text to return the Gridview to it's default state
txtSearch.Text = "";
SearchString = "";
gvDetails.DataBind();
}
}



Thursday, 30 May 2013

Drop Down List Attached With Selection Of Another Drop Down Like Country,State,City Selection

Demo:-



Instruction:- To Execute this code first of all make three table in a Database.which are are connected to each other with unique id.Simply make three tables like this..


CountryTable 

StateTable 


CityTable  


And now these are design & code Behind Paste this code in your file

Design Code:-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CountryDropdowns.aspx.cs" Inherits="CountryDropdowns" %>
<!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>CasCading Dropdowns Sample</title>
    <style type="text/css">
        .style1
        {
            height: 30px;
        }
    </style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table align="center" cellpadding="10px" cellspacing="5" style="background:skyblue;width:400px;border:solid 2px darkred;padding:8px;">
<tr>
<td colspan="2" valign="bottom" class="style1">
<h3>Drop Down Menu Attached With Selection Of One Another</h3> <hr />
</td>
</tr>
<tr>
<td>
Select Country:
</td>
<td>
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCountry_SelectedIndexChanged" Height="16px"
        Width="119px"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
Select State:
</td>
<td>
<asp:DropDownList ID="ddlState" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlState_SelectedIndexChanged" Height="18px" Width="122px"></asp:DropDownList>
</td>
</tr>
<tr>
<td>
Select City:
</td>
<td>
<asp:DropDownList ID="ddlRegion" runat="server" Height="19px" Width="125px"></asp:DropDownList>
</td>
</tr>
<tr><td></td><td style="font-size:small" align="right">R.Upadhyay</td></tr>
</table>
</div>
</form>
</body>
</html>


Code Behind:-


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

public partial class CountryDropdowns : System.Web.UI.Page
{
private String strConnection = "Data Source=IT-HP\\sqlexpress;Initial Catalog=Employee;Integrated Security=True";
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindContrydropdown();
}
}
protected void BindContrydropdown()
{
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from CountryTable", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlCountry.DataSource = ds;
ddlCountry.DataTextField = "CountryName";
ddlCountry.DataValueField = "CountryID";
ddlCountry.DataBind();
ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
int CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from StateTable where CountryID="+CountryID, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlState.DataSource = ds;
ddlState.DataTextField = "StateName";
ddlState.DataValueField = "StateID";
ddlState.DataBind();
ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
if(ddlState.SelectedValue=="0")
{
ddlRegion.Items.Clear();
ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));
}
}
protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
{
int StateID = Convert.ToInt32(ddlState.SelectedValue);
SqlConnection con = new SqlConnection(strConnection);
con.Open();
SqlCommand cmd = new SqlCommand("select * from CityTable where StateID=" + StateID, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlRegion.DataSource = ds;
ddlRegion.DataTextField = "CityName";
ddlRegion.DataValueField = "CityID";
ddlRegion.DataBind();
ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));
}
}



Tuesday, 28 May 2013

Zoom Out & Zoom In Using Jquery in Asp.net

Demo:-

Instruction:- To Use this code Download jquery-1.9.1.min.js from http://jquery.com/download/ and link as shown in code below.

Code:-

<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#b4').click(function()
{
$('#d1').animate({width:'+=60px',height:'+=40px'},1000);
});
$('#b5').click(function()
{
$('#d1').animate({width:'-=60px',height:'-=40px'},1000);
});
});
function d1_onclick() {
}
</script>
</head>
<body>
<img id="d1" src="Berlin Falls.jpg" style="width:150;height:100; onclick="return d1_onclick()" />
<br><br><hr><br>
<br />
        
<input id="b5" type="button" value="Zoom Out"/>
        <input id="b4" type="button" value="Zoom In" />
</body>
</html>





Sunday, 26 May 2013

JQuery Show Hide Option Theme Change & Using Buttons

Demo:-




Instruction:- To Use this code Download jquery-1.9.1.min.js from http://jquery.com/download/ and link as shown in code below.

Code:-


<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#b1').click(function()
{
$('#d1').css({background:'lightyellow',border:'solid 2px darkgreen',color:'darkgreen',padding:'12px',width:'300px'});
});
$('#b2').click(function()
{
$('#d1').css({background:'smokewhite',border:'solid 2px darkred',color:'darkred',padding:'12px',width:'300px'});
});
$('#b3').click(function()
{
$('#d1').css({background:'skyblue',border:'solid 2px darkblue',color:'darkblue',padding:'12px',width:'300px'});
});
$('#b11').click(function()
{
$('#d2').removeClass();
$('#d2').addClass('green');
});
$('#b22').click(function()
{
$('#d2').removeClass();
$('#d2').addClass('red');
});
$('#b33').click(function()
{
$('#d2').removeClass();
$('#d2').addClass('blue');
});
$('#btnShow').click(function()
{
$('#d1').show('fadeIn');
});
$('#btnHide').click(function()
{
$('#d1').hide('fadeOut');
});
$('#btnToggle').click(function()
{
$('#d2').toggle('slow');
});
});
</script> <style type="text/css">
.green{background:lightyellow;border:solid 2px darkgreen;color:darkgreen;padding:12px;width:300px}
.red{background:pink;border:solid 2px darkred;color:darkred;padding:12px;width:300px}
.blue{background:skyblue;border:solid 2px darkblue;color:darkblue;padding:12px;width:300px}
</style>
</head>
<body>
<div id="d1" style="width:150;height:100;">
<a href="http://aspdotnetstudio.blogspot.in/"><h2>Aspdotnet Studio<h2></a>

</div>
<br><br><hr><br>
<input id="b1" type="button" value="Green Theme"/>
<input id="b2" type="button" value="Red Theme"/>
<input id="b3" type="button" value="Blue Theme"/>
<input id="btnHide" type="button" value="hide"/>
<input id="btnShow" type="button" value="show"/>
</body>
</html>

Wednesday, 22 May 2013

Disable Autofilling in all browser on Web Page Text Box

Demo:-


Instruction:- In This we use Autocomplete Property.

autocomplete="off" 

Design 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 id="Head1" runat="server">
<title>Disable Autofilling in all browser on Web Page Text Box</title>
<style type="text/css">
.Button
{
background-color :#0066CC;
color: #FFFFFF;
font-weight: bold;
margin-right: 2px;
padding: 4px 20px 4px 21px;
}
</style>
</head>
<body>
<form id="form1" runat="server" autocomplete="off">
<fieldset style="height: 242px; width: 470px">
<legend>Contact Us</legend>
<table cellspacing="2" cellpadding="2" border="0">


<tr><td>Name:-</td><td><asp:TextBox ID="txtName" runat="server" /></td></tr>


<tr><td>Email:-</td><td><asp:TextBox ID="txtEmail" runat="server" /></td></tr>

<tr><td>Subject:-</td><td><asp:TextBox ID="txtSubject" runat="server" /></td></tr>

<tr><td valign="top">Query:-</td>

<td> <asp:TextBox ID="txtMessage" Rows="5" Columns="40" TextMode="MultiLine" runat="server"/></td></tr>
<tr>
<td><asp:button ID="btnSubmitt" Text="Submit"  runat="server" onclick="btn_Click" CssClass="Button"/></td></tr>
<tr><td colspan="2" style=" color:red"><asp:Label ID="lbltxt" runat="server"/></td></tr>
</table>
</fieldset>
</form>
</body>
</html>

Tuesday, 21 May 2013

Right Click Disable On Picture and Page In Asp.net

Demo:-


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>Restrict Right Click</title>
   
    <script type="text/javascript">
function disableRightClick()
{
alert("Right Click not Allowed !!");
return false;
}
</script>
   
</head>
<body oncontextmenu=" return disableRightClick();">
    <form id="form1" runat="server">
    <div>
    <asp:Image ID="img1" runat="server" ImageUrl="~/1.jpeg" Width="261px"
            oncontextmenu="return false;" Height="214px" />
   
    </div>
    </form>
</body>
</html>



Monday, 20 May 2013

Set Default Focus on Page Or Text Box Using Default Focus Property Asp.net

Instruction:- In this we use this property

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



Demo:-



Code:-


<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Set Default Focus On a Page Or Text Boxes</title>
</head>
<body>
    <form id="form1" runat="server" defaultfocus="TxtUserId">
    <div>
        <h2 style="color:red">Default Focus </h2>
     
       <table><tr><td>
        <asp:Label ID="Label1" runat="server" Font-Bold="true" ForeColor="Orange"  Text="User Name"     >
        </asp:Label>
        </td>
        <td>
        <asp:TextBox     ID="TxtUserName"  runat="server" BackColor="Orange"        >
        </asp:TextBox>
        </td>
        </tr>
        <tr><td>
        <asp:Label  ID="Label2" runat="server" Font-Bold="true" ForeColor="Orange"  Text="User Id"      >
        </asp:Label>
        </td>
        <td>
        <asp:TextBox   ID="TxtUserId" runat="server" BackColor="Orange"   >   </asp:TextBox>
      </td>
      <tr><td colspan=2><center><asp:Button  ID="Button1" runat="server" Font-Bold="true"  ForeColor="Black" Text="Submit"         /></center></td></tr>
     
        </tr>
        </table>
    </div>
    </form>
</body>
</html>

Sunday, 19 May 2013

Alert Message Box Using Javascript Codebehind Asp.net.

Demo:-
                   


Design Code:-

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>
<!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 id="Head1" runat="server">
<title>Aspdotnet Studio</title>
<script type="text/javascript">
function Showalert() {
alert('Alert  from codebehind');
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnS" runat="server" Text="Show alert" onclick="btnS_Click" />
<asp:Button ID="btnC" runat="server" Text="Call JavaScript Function"
onclick="btnC_Click" />
</div>
</form>
</body>
</html>

Code Behind:-

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnS_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this,GetType(),"showalert","alert('This is Simple Alert Message');",true);
}
protected void btnC_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "Showalert();", true);
}
}


Friday, 17 May 2013

Check User Name is Available Or Not Using Asp.net

Demo:-


Design Code:-


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" EnableEventValidation="false" %>
<!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>Check Username availability Using Ajax</title>
    <style type="text/css">
    .waitingdiv {
    background-color: #F5F8FA;
    border: 1px solid #5A768E;
    color: #333333;
    font-size: 93%;
    margin-bottom: 1em;
    margin-top: 0.2em;
    padding: 8px 12px;
    width: 8.4em;
}
</style>
   
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scriptmanager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
function BeginRequestHandler(sender, args) {
var state = document.getElementById('loadingdiv').style.display;
if (state == 'block') {
document.getElementById('loadingdiv').style.display = 'none';
} else {
document.getElementById('loadingdiv').style.display = 'block';
}
args.get_postBackElement().disabled = true;
}
</script>
     <div>
   
     <asp:UpdatePanel ID="PnlUsrDetails" runat="server">
    <ContentTemplate>
    <table>
    <tr>
    <td>
    UserName:
    </td>
    <td>
       <asp:TextBox ID="txtUsername" runat="server" AutoPostBack="true" ontextchanged="txtUsername_TextChanged"/>
    </td>
    <td>
      <div id="checkusername" runat="server"  Visible="false">
        <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px"/>
        <asp:Label ID="lblStatus" runat="server"></asp:Label>
    </div>
    </td>
    </tr>
    </table>
    <div class="waitingdiv" id="loadingdiv" style="display:none; margin-left:5.3em">
    <img src="LoadingImage.gif" alt="Loading" />Wait a movment...
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

Code Behind:-


using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
protected void txtUsername_TextChanged(object sender, EventArgs e)
{
if(!string.IsNullOrEmpty(txtUsername.Text))
{
SqlConnection con = new SqlConnection("Data Source=IT-HP\\sqlexpress;Initial Catalog=Employee;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName=@Name", con);
cmd.Parameters.AddWithValue("@Name", txtUsername.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
checkusername.Visible = true;
imgstatus.ImageUrl = "NotAvailable.jpg";
lblStatus.Text = "Username is not Available";
System.Threading.Thread.Sleep(2000);
}
else
{
checkusername.Visible = true;
imgstatus.ImageUrl = "Icon_Available.gif";
lblStatus.Text = "UserName Available";
System.Threading.Thread.Sleep(2000);
}}
else
{
checkusername.Visible = false;
}}}