Wednesday 14 September 2011

How to kill process in .net

Private Sub Button1_Click
(ByVal sender As System.Object,
 ByVal e As System.EventArgs) Handles Button1.Click

Dim pProcess() As Process = 
System.Diagnostics.Process.GetProcessesByName("EXCEL")
For Each p As Process In pProcess
            p.Kill()
        Next

        Dim pProcess2() As Process = 
        System.Diagnostics.Process.
        GetProcessesByName("POWERPNT")

        For Each p As Process In pProcess2
           p.Kill()
        Next
    End Sub

Microsoft Windows Operating System Version Validation (XP


Private Sub GetOperatingSystemVersions()

        Dim OSVersion As System.OperatingSystem = 
         System.Environment.OSVersion
        If OSVersion.Version.Major.ToString.Trim <> "5" Then
            ''Not Windows XP

            System.Windows.MessageBox.Show
("Please Note: Only Computers which are using 
the Microsoft Windows XP System can use this 
Application at this time. The Application will 
be closed.", "Computer Operating System In Use 
Is Not Supported", MessageBoxButton.OK, 
MessageBoxImage.Exclamation)

            ''Stop App
            End
        End If
    End Sub

Saturday 10 September 2011

How to make Gridview Row color on Mouse Over Event using CSS


<style type="text/css">
    #GridView1 tr.rowHover:hover
    {
        background-color: pink;
        font-family: Arial;
    }
</style>
 
How To Apply

<asp:GridView ID="GridView1" runat="server" RowStyle-CssClass="rowHover">
</asp:GridView>
 

How To Disable selection, Copy in your Web Page Using CSS

<style type="text/css">
    .protectedText
    {   
        /*-moz-user-focus: ignore;   
        -moz-user-select: none;
        -moz-user-selectall: none;*/
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -o-user-select: none;
         user-select: none;
     }
</style>
 
How to Apply given Below: 
 
<body ondragstart="return false;" 
onselectstart="return false;" class="protectedText"> 

How to use Session Value in JavaScript


<script type="text/javascript" language="javascript">
window.onload = function()
{
 var sampleColor = '<%=Session["Color"]%>';
 alert(sampleColor);
}
</script>

Friday 9 September 2011

How to validate Numeric Text Box using javascrit


Description : A text Box will not accept Character value in itself.

function validateInt(Mobile,msg)
{
      var o = Mobile.value;
      if(o.length!=0)
      {
     if(isNaN(o))
      {    
            alert(msg)  
            Mobile.value="";
            Mobile.focus();
            return false;
       }
      }
   }

OR
Best Code


<Script Type = "Javascript">
function numbersonly(e)
    {
//alert('hi');
var unicode=e.charCode? e.charCode : e.keyCode;
if (unicode!=8 && unicode!=46 && unicode!=9)
{
if (unicode<48||unicode>57)
return false
}
}


How to access

<asp:TextBox ID="TextBox1" runat="server" onkeypress="return numbersonly(event);"></asp:TextBox>
 

Best Date Validation using Javascript


function chkdate(inpdate)
{
idate=inpdate.value;
if(idate.length!=0)
{
if (idate.length > 10)
{
alert("date cannot exceed more than 10 characters and should be in format dd/mm/yyyy") ;
inpdate.focus();
inpdate.value=" ";
return false;
}
var dsh1 = idate.substring(3,2);
//alert (dsh1);
var dsh2 = idate.substring(6,5);
//alert (dsh2);
if (dsh1 != "/" )
{
alert ("Enter date in dd/mm/yyyy format >>> there is no '/' after day ");
inpdate.focus();
inpdate.value="";
return false
}
if (dsh2 != "/" )
{
alert ("Enter date in dd/mm/yyyy format >>> there is no '/' after month ");
inpdate.focus();
inpdate.value="";
return false;
}
var yr=idate.substring(6,10);
var mm=idate.substring(3,5);
var dd=idate.substring(0,2);
//alert(yr+' Year');
//alert(mm+' Month');
//alert(dd+' Day');
if (isNaN(dd))
{
alert ("Day of month should be numeric ");
inpdate.focus();
inpdate.value="";

return false;
}
if (isNaN(mm))
{
alert ("Month should be numeric ");
inpdate.focus();
inpdate.value="";

return false;
}
if (isNaN(yr))
{
alert ("Year should be numeric ");
inpdate.focus();
inpdate.value="";

return false;
}
if (yr < 1900)
{
alert ("Year should be greater than 1900 ");
inpdate.focus();
inpdate.value="";
return false;
}
//if(yr>2010)
//{
//alert("Year should be less than 2011");
//inpdate.focus();
//inpdate.value="";
//return false;
//}
if (yr.length != 4 )
{
alert ("Year should be 4 digits in year");
inpdate.focus();
inpdate.value="";
return false;
}
if (dd < 1)
{
alert ("Day of month cannot be less than 1 ");
inpdate.focus();
inpdate.value="";
return false;
}
if (dd > 31 )
{
alert ("Day cannot be Greater than 31 ");
inpdate.focus();
inpdate.value="";
return false;
}

if (mm > 12 || mm < 1 ) {
alert ("Month should be between 1 and 12 ");
inpdate.focus();
inpdate.value="";

return false;
}
if (mm == 6 || mm == 9 || mm==11 ) {
if (dd > 30 ) {
alert ("There are 30 days in June, September and November !! please correct day ");
inpdate.focus();
inpdate.value="";

return false;
}
}
if (mm==2)
{

var b=parseInt(yr /4);
if (isNaN(b)) {
alert( "Check no.of days in February NOT valid");
inpdate.focus();
inpdate.value="";

return false ;
}
if (dd>29) {
alert("Check no.of days in February NOT valid days in February cannot exceed 29");
inpdate.focus();
inpdate.value="";

return false ;
}
if (dd==29 && ((yr/4)!=parseInt(yr/4))) {
alert( "Check no.of days !! This is NOt leap year ");
inpdate.focus();
inpdate.value="";
return false ;
}
}
}
return true ;
}

How to call : onblur="chkdate(txtDoexp);"

How to set Window Position and Size Using Javascirpt


<script type="text/javascript">  
function changeScreenSize(w,h)
     {   
    
//     window.offsetX=0;
//     Window.offsetY=0;
     window.resizeTo( w,h ) 
     self.moveTo(0,0);  
     }
</script>

How to Call : <body onload="changeScreenSize(500,1000)">

Javascript Code for Block work of Back space key, Enter key and All Character and Sign keys


function CHKNUM(e,idtxt)
 { 
    var txt = document.getElementById(idtxt);

    if(e.keyCode < 48 || e.keyCode > 57)// && ( keyCode != 8 || e.keyCode != 13))
    {
   
    if(e.keyCode != 13 && e.keyCode != 8)
    { 
      alert("keyCode for the key pressed: " + e.keyCode + "\n");
      alert("Please enter Numbers Only.");
      txt.value="";
      txt.focus();
      return false;
      }

    }
    else
    {
     return true;
    }
 }

How to Check Browser Version


function checkBrowser()
{

var version = 999; // we assume a sane browser
if (navigator.appVersion.indexOf("MSIE") != -1)
version =parseFloat(navigator.appVersion.split("MSIE")[0]);
   // return version;
//    alert(version);
if(version < 8.0)
{
alert(version);
}
document.getElementById("a2").style.width = '150px';

   // alert(window.navigator.appVersion);
}

How to set Menu Size according to Browser in Java Script


function setMenuSize()
{
var mfund = document.getElementById("Mfund");
var brow=((navigator.appName) +
(parseInt(navigator.appVersion)));

//if(parseInt(navigator.appVersion >=4))
//{
if(brow == "Microsoft Internet Explorer4")
{
//alert('hi');
document.getElementById("a2").style.width = '150px';

}
}

Java script of Change password


var msg="The following fields are necessary\n\n"
var a=document.form1.txtOld.value.length;
var b=document.form1.txtNew.value.length;
var c=document.form1.txtConfirm.value.length;

var NewPwd = document.getElementById("txtNew").value;
var ConfirmPwd = document.getElementById("txtConfirm").value;
 
if(a==0)
{
msg=msg+"* Old Password\n";
alert(msg);
document.getElementById("txtOld").focus();
}
else if(b==0)
{
msg=msg+"* New password\n";
alert(msg);
document.getElementById("txtNew").focus();
}
else if(c==0)
{
msg=msg+"* confirm Password \n";
alert(msg);
document.getElementById("txtConfirm").focus();
}
else if(NewPwd!=ConfirmPwd)
{
alert('New Password and Confirm Password did not mathed');
document.getElementById("txtNew").value= '';
document.getElementById("txtConfirm").value= '';
document.getElementById("txtNew").focus();
}
else
{
return true;
}
return false
}

How to Bind Java script from Code Behind


Note: Given Below Example BlankField()is java script Function
      onClick is Event.

btnSub.Attributes.Add("onClick", "return BlankField()")
       
txtPremPayemtPred.Attributes.Add("onkeypress", "return CHKNUM(event,'" & txtPremPayemtPred.ClientID & "')")

Wednesday 7 September 2011

How to delete duplicate records from a Table (just copy paste it)


Note: it some times happen whenever a table 
do not have primary and it 
consist Duplicate Records
 
--Create Table
 
create table dupemp
 (
name varchar(20),salary int,deptno int
)

select * from dupemp

--Insert Records

insert into dupemp(name,salary,deptno) values('inthiyaaz',2000,10)

insert into dupemp(name,salary,deptno) values('inthiyaaz',2000,10)

insert into dupemp(name,salary,deptno) values('inthiyaaz',2000,10)

insert into dupemp(name,salary,deptno) values('inthiyaaz',2000,10)

insert into dupemp(name,salary,deptno) values('inthiyaaz',2000,10)

insert into dupemp(name,salary,deptno) values('Khaja',3000,20)

insert into dupemp(name,salary,deptno) values('Khaja',3000,20)

insert into dupemp(name,salary,deptno) values('Naseeb',3000,20)

--Main Query to find and delete 
Duplicate Records

with CTE as(select row_number() over(partition by name order by name) row,name,salary,deptno from dupemp )
delete from CTE where row>1