Welcome

Hello, Welcome to my blog. If you like feel free to refer others

Wednesday, 27 June 2012

Printing the content of div or panel

In general, we required to print the content of a portion of page. We don't need that whole page will get printed. So here I am going to provide a small java script function that can solve this problem.
Here is the code for print a specific area.

function PrintDiv() {    
var prtContent = document.getElementById('<%=divPrintArea.ClientID%>');   
var WinPrint = window.open('', '', 'left=0,top=0,width=900,height=600,
toolbar=1,scrollbars=1,status=0');    
WinPrint.document.write(prtContent.innerHTML);    
WinPrint.document.close();   
WinPrint.focus();   
WinPrint.print();   
WinPrint.close();    
}

Javascript function to check integer value

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

Making a button default clickable when enter key is pressed

Many times we want that on pressing enter key the submit button should be automatic click. For example on login page after typing password generally users press enter key and want that submit button will call but nothing happen.
 Here is the JavaScript code for it:


function doClick(buttonName, e) {
            var key;
            if (window.event)
                        key = window.event.keyCode;     //IE
            else
                        key = e.which;     //firefox
            if (key == 13) {   //Get the button the user wants to have clicked
                        var btn = document.getElementById(buttonName);
                        if (btn != null) { //If we find the button click it
                                    btn.click();
                                    event.keyCode = 0
                        }
            }
}

Tuesday, 26 June 2012

How to check if a string contains special character using javascript


Sometimes we need to check if a string contains any special charachter. Ex. name should not contains any special character.

Here is the code for it : 

function IsSpecialChar(strString)
//  check for valid SpecialChar strings
{
    var strValidChars = "<>@!#$%^&*()_+[]{}?:;|'\"\\,./~`-=";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}




Happy Learning......

Friday, 16 March 2012

How to stop the !New tag from appearing when you add items to your SharePoint Team Services and SharePoint Services Web site

To stop the !New tag from appearing for new entries on your Windows SharePoint Services Web site, follow these steps, as appropriate for your version of SharePoint Services.

Windows SharePoint Services 3.0 Web site

To stop the !New tag from appearing next to new entries on a Windows SharePoint Services 3.0 Web site, use the Stsadm.exe tool to change the "Days to Show New Icon" property to zero. 

To do this, follow these steps:
  1. Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
  2. Type the following commands, and then press ENTER after each command:
    cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\12\BIN
    stsadm.exe -o setproperty -pn days-to-show-new-icon -pv 0 -url [Your Virtual Server's URL]

Windows SharePoint Services Web site

To stop the !New tag from appearing next to new entries on a Windows SharePoint Services Web site, use the Stsadm.exe tool to change the "Days to Show New Icon" property to zero. 

To do this, follow these steps:
  1. Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
  2. Type the following commands, and then press ENTER after each command:
    cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\60\BIN
    stsadm.exe -o setproperty -pn days-to-show-new-icon -pv 0 -url [Your Virtual Server's URL]

SharePoint Team Services Web site

To stop the !New tag from appearing next to new entries on a SharePoint Team Services Web site, use the Owsadm.exe tool to change the "New Item Display Cutoff" property to zero.

To do this, follow these steps:
  1. Click Start, point to All Programs, point to Accessories, and then click Command Prompt.
  2. Type the following commands, and then press ENTER after each command:
    cd /d %programfiles%\Common Files\Microsoft Shared\Web Server Extensions\50\BIN
    owsadm.exe -o setproperty -pn NewItemDisplayCutoff -pv 0 -p [Your Virtual Server's Port]

    Source : msdn

Thursday, 9 February 2012

Creating Shared Assembly or GAC Assembly and accessing


Creating an assembly key file

The steps involved in adding an assembly to the GAC is not as simple as adding the assembly to a web application. Since all applications can access this library, some security precautions have been taken by Microsoft to ensure uniqueness, version protection, and code integrity. This is achieved by creating a strong name for your new assembly. A Strong Name consists of the assembly identity and also a public key and digital signature. To create a strong name, you use the syntax:
sn -k StrongNameFile.snk
Adding StrongNameFile.snk entry and modifying the version in AssemblyInfo.cs
[assembly: AssemblyVersion("1.0.1.1")]
[assembly: AssemblyKeyFile("c:\\StrongNameFile.snk")]

Adding your assembly to your GAC
gacutil /i AssemblyFileName.dll

Adding your assembly machine.config
<assembly="AssemblyFileName,Version=0.0.0.0,Culture=neutral,PublicKeyToken=5edf592a9c40680c">
Using Shared Assembly

<%@Import Namespace="Ashis"%>

Happy learning......

Insert IDENTITY column by IDENTITY_INSERT ON


Problem: If a column in a table have identity on a


Explanation:


CREATE TABLE dbo.Tool(
   ID INT IDENTITY NOT NULL PRIMARY KEY,
   Name VARCHAR(40) NOT NULL
)
GO
-- Inserting values into products table.
INSERT INTO dbo.Tool(Name) VALUES ('Screwdriver')
INSERT INTO dbo.Tool(Name) VALUES ('Hammer')
INSERT INTO dbo.Tool(Name) VALUES ('Saw')
INSERT INTO dbo.Tool(Name) VALUES ('Shovel')
GO

-- Create a gap in the identity values.
DELETE dbo.Tool
WHERE Name = 'Saw'
GO

SELECT *
FROM dbo.Tool
GO

-- Try to insert an explicit ID value of 3;
-- should return a warning.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO
-- SET IDENTITY_INSERT to ON.
SET IDENTITY_INSERT dbo.Tool ON
GO

-- Try to insert an explicit ID value of 3.
INSERT INTO dbo.Tool (ID, Name) VALUES (3, 'Garden shovel')
GO

SELECT *
FROM dbo.Tool
GO
-- Drop products table.
DROP TABLE dbo.Tool
GO



Happy Learning......