Feed on
Posts
Comments

<html>
<head>

<script type=”text/javascript”>
var shiftOn = false;
var ctrlOn = false;
var altOn = false;
var focusedValue = “0″;

function validateNumeric(obj)
{
if (obj.value.length == 0)
{
obj.value = focusedValue;
return false;
}
else if (obj.value.indexOf(”-”) > 0)
{
obj.value = focusedValue;
return false;
}
else
{
for (var i = 0; i 47) && (keynum 95) && (keynum < 106))) //Numeric
{
switch(keynum)
{
case 8: //Backspace
case 9: //Tab
case 35: //End
case 36: //Home
case 37: //Left Arrow
case 39: //Right Arrow
case 46: //Delete
return true;

case 13: //Enter
case 27: //Esc
obj.blur();
return true;

case 16: //Shift
shiftOn = true;
return true;

case 17: //Ctrl
ctrlOn = true;
return true;

case 18: //Alt
altOn = true;
return false;

case 109: //Minus sign
case 189: //Minus sign
if (obj.value.indexOf(”-”) != -1)
{
return false;
}
else
{
return true;
}

default:
return false;
}
}

return true;
}

function handleKeyUp(e)
{
var keynum;

if (window.event != null) //IE
{
keynum = e.keyCode;
}
else if (e.which != null) //Other
{
keynum = e.which;
}

switch(keynum)
{
case 16: //Shift
shiftOn = false;
break;

case 17: //Ctrl
ctrlOn = false;
break;

case 18: //Alt
altOn = false;
break;
}
}

function handleFocus(obj)
{
focusedValue = obj.value;
obj.select();
}

function handleBlur(obj)
{
validateNumeric(obj);
obj.value = obj.value;
}
</script>

</head>
<body onload=”myText.focus()”>
<input id=”myText” type=”text” onkeydown=”return handleKeyDown(event, this)” onkeyup=”handleKeyUp(event)” onfocus=”handleFocus(this)”
onblur=”handleBlur(this)” /><br />
<br />
<input id=”Text1″ type=”text” />
</body>
</html>

<html>
<head>
<title>Demo</title>
<script type=”text/javascript”>
function textChanged(elm)
{
alert(elm.value);
}

onload = function()
{
var elm = document.getElementById(”mytextbox”);
elm.onchange = new Function(’textChanged(this)’);
}
</script>
</head>
<body>
<input id=”mytextbox” type=”text”/>
</body>
</html>

<input type=”text” id=”mytb” />

To select: document.getElementById(”mytb”).select()

To unselect: document.getElementById(”mytb”).value = document.getElementById(”mytb”).value;

Just the value to itself. That’s all!

SQL Types In SYSOBJECTS

The query:

 

select 

distinct type from sysobjects

FN: Scalar Valued Functions
P: Stored Procedures
U: Tables
TF Table Valued Functions

How to delete all of the same type?

use

mydb –replace by your own db name

GO

declare

@procName sysnamedeclare

someCursor cursor FORselect

name from sysobjects where type = ‘P’ AND objectproperty(id, ‘IsMSShipped’) = 0 order by name ascopen

someCursor

fetch

next from someCursor into @procName

while

@@FETCH_STATUS = 0

begin

 

exec(‘drop proc ‘ + @procName)

 

fetch next from someCursor into @procName

end

close

someCursor

deallocate

someCursorgo

 

 


            GridViewRow pager = SearchResultsGridView.TopPagerRow;

            if (pager != null)
            {
                int pageCount = PageCount; // SearchResultsGridView.PageCount;
                int pageSize = SearchResultsGridView.PageSize;
                int columnCount = 10;

                if (pageCount > 1)
                {
                    Label pagerLabel = (Label)pager.Cells[0].FindControl("PagerLabel");
                    pagerLabel.Text = pagerLabel.Text.Replace("<transactions>", ResultCount.ToString());
                    pagerLabel.Text = pagerLabel.Text.Replace("<start>", (((CurrentPage) * SearchResultsGridView.PageSize) + 1).ToString());
                    pagerLabel.Text = pagerLabel.Text.Replace("<end>", (((CurrentPage + 1) * SearchResultsGridView.PageSize)).ToString());
                    PlaceHolder pagerPlaceHolder = (PlaceHolder)pager.Cells[0].FindControl("PlaceHolder1");
                    bool breakLoop = false;

                    if (pagerPlaceHolder != null)
                    {
                        Table myTable = new Table();
                        int rowCount = (pageCount / columnCount) + (((pageCount % columnCount) == 0) ? 0 : 1);

                        for (int row = 0; row < rowCount; row++)
                        {
                            int firstPageInRow = row * columnCount;
                            int lastPageInRow = ((firstPageInRow + columnCount - 1) < pageCount) ?
                                                 (firstPageInRow + columnCount - 1) : pageCount - 1;
                            TableRow myRow = new TableRow();

                            for (int column = 0; column < columnCount; column++)
                            {
                                // build the row out of the pageCount for the column
                                TableCell myColumn = new TableCell();
                                int startingRecord = (row * columnCount * pageSize) + (column * pageSize) + 1;
                                int endingRecord = (row * columnCount * pageSize) + (column * pageSize) + pageSize;

                                if (endingRecord > ResultCount)
                                {
                                    endingRecord = ResultCount;
                                    breakLoop = true;
                                }

                                string pageLabel = startingRecord + " - " + endingRecord;
                                int page = (row * columnCount) + column;

                                if (page == CurrentPage)
                                {
                                    // display a Label instead of a LinkButton
                                    Label label = new Label();
                                    label.Text = pageLabel;
                                    //label.ID = "Page" + (page + 1).ToString();
                                    myColumn.Controls.Add(label);
                                }
                                else
                                {
                                    // diplay a LinkButton for the page
                                    LinkButton button = new LinkButton();
                                    button.Text = pageLabel;
                                    button.CommandName = "Page";
                                    button.CommandArgument = (page + 1).ToString();
                                    //button.ID = "Page" + (page + 1).ToString();
                                    myColumn.Controls.Add(button);
                                }

                                myRow.Cells.Add(myColumn);

                                if (breakLoop)
                                {
                                    break;
                                }
                            }

                            myTable.Rows.Add(myRow);

                            if (breakLoop)
                            {
                                break;
                            }
                        }

                        pagerPlaceHolder.Controls.Add(myTable);
                    }

                    pager.Visible = true;
                }
                else
                {
                    pager.Visible = false;
                }
            }

DECLARE @Items VARCHAR(1000)
SET @Items = ‘A,B,CD,E,FGH,KL,MNOP,QRSTU,V,W,XYZ’
DECLARE @Item VARCHAR(50)
DECLARE @Pos INT
DECLARE @Loop BIT
SELECT @Loop = CASE WHEN LEN(@Items) > 0 THEN 1 ELSE 0 END
WHILE (SELECT @Loop) = 1
BEGIN
SELECT @Pos = CHARINDEX(’,', @Items, 1)
IF @Pos > 0
BEGIN
SELECT @Item = SUBSTRING(@Items, 1, @Pos - 1)
SELECT @Items = SUBSTRING(@Items, @Pos + 1, LEN(@Items) - @Pos)
END
ELSE
BEGIN
SELECT @Item = @Items
SELECT @Loop = 0
END
END

Preloading Images In Javascript

<html><head>

<script type=”text/javascript”>

img2=new Image();img2.src=“landscape3.gif”;

function changeImage(){

document.getElementById(‘myImage’).src=img2.src;}

</script></head><body>

<p>

When you mouse over the image, a new image will appear.</p>

<img id=”myImage” onmouseover=”changeImage()” border=”0″ width=”160″ height=”120″

src=”landscape2.jpg”>

<p>

The new image appears instantly, because your browser has already loaded the image.</p></body></html>

<%@ 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>Untitled Page</title></head><body>

<form id=”form1″ runat=”server”>

<div>

<script type=”text/javascript”>

var BrowserDetect = {init: function () {

this.browser = this.searchString(this.dataBrowser) || “An unknown browser”;this.version = this.searchVersion(navigator.userAgent)||

this.searchVersion(navigator.appVersion)|| “an unknown version”;

this.OS = this.searchString(this.dataOS) || “an unknown OS”;},

searchString: function (data) {for (var i=0;i<data.length;i++) {

var dataString = data[i].string;var dataProp = data[i].prop;

this.versionSearchString = data[i].versionSearch || data[i].identity;if (dataString) {

if (dataString.indexOf(data[i].subString) != -1)return data[i].identity;}

else if (dataProp)

return data[i].identity;}

},

searchVersion: function (dataString) {var index = dataString.indexOf(this.versionSearchString);

if (index == -1) return;return parseFloat(dataString.substring(index+this.versionSearchString.length+1));},

dataBrowser: [

{ string: navigator.userAgent,

subString: "OmniWeb",versionSearch: "OmniWeb/",identity: "OmniWeb"

},

{

string: navigator.vendor,

subString: "Apple",identity: "Safari"

},

{

prop: window.opera,

identity: "Opera"

},

{

string: navigator.vendor,

subString: "iCab",identity: "iCab"

},

{

string: navigator.vendor,

subString: "KDE",identity: "Konqueror"

},

{

string: navigator.userAgent,

subString: "Firefox",identity: "Firefox"

},

{

string: navigator.vendor,

subString: "Camino",identity: "Camino"

},

{ // for newer Netscapes (6+)

string: navigator.userAgent,

subString: "Netscape",identity: "Netscape"

},

{

string: navigator.userAgent,

subString: "MSIE",identity: "Explorer",versionSearch: "MSIE"

},

{

string: navigator.userAgent,

subString: "Gecko",identity: "Mozilla",versionSearch: "rv"

},

{ // for older Netscapes (4-)

string: navigator.userAgent,

subString: "Mozilla",identity: "Netscape",versionSearch: "Mozilla"

}

],

dataOS : [

{

string: navigator.platform,

subString: "Win",identity: "Windows"

},

{

string: navigator.platform,

subString: "Mac",identity: "Mac"

},

{

string: navigator.platform,

subString: "Linux",identity: "Linux"

}

]

};

BrowserDetect.init();

</script>

<script type=”text/javascript”>

document.write(‘<p class=”accent”>You\’re using ‘ + BrowserDetect.browser + ‘ ‘ + BrowserDetect.version + ‘ on ‘ + BrowserDetect.OS + ‘!</p>’);</script>

</div>

</form></body></html>

The script:

USE SomeDB    

DECLARE @name varchar(128), @sql varchar(500)    

DECLARE procs CURSOR FAST_FORWARD FOR    

SELECT name FROM sysobjects WHERE type = ‘U’ ORDER BY name ASC FOR READ ONLY    

OPEN procs    

FETCH next FROM procs INTO @name    

WHILE @@FETCH_STATUS = 0    

BEGIN    

SELECT @sql = ‘Grant execute on ‘ + LTRIM(RTRIM(@name)) + ‘ to SomeUser’    

EXEC(@sql)    

PRINT @sqlFETCH next FROM procs INTO @name    

END    

CLOSE procs    

DEALLOCATE procs

X509 Certificate Installation

Here are the steps of installing an X509 certificate in windows:

Installation Steps for DEVAssumptions:

  • The Microsoft Windows SDK exists on the machine
  • The certificate name is SomeName

  1. Go to Start > All Programs > Microsoft Windows SDK > CMD Shell
  2. Execute the following command: makecert -r -pe -n “CN=SomeName” -b 01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr LocalMachine -sky exchange -sp “Microsoft RSA SChannel Cryptographic Provider” -sy 12
  3. Copy the executable findprivatekey.exe to an arbitrary folder
  4. Go to Start > Run type cmd
  5. Browse to the folder where the findprivatekey.exe was copied
  6. Execute the following command: findprivatekey.exe My LocalMachine -n “CN=SomeName” -a
  7. Copy the output of that command in Notepad
  8. Remove all line breaks if you see any
  9. Replace the {output from above} by the text from step 8 and execute the following command:  cacls “{output from above}” /E /P NETWORKSERVICE:R Example: cacls “C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\9e7f481ca4127144bc75102dabb32ad0_c18e0de9-0e80-4436-920c-4ab1cae7939a” /E /P NETWORKSERVICE:R
  10. You’re done!

 Installation Steps for QA/ProdAssumptions:

  • The Microsoft Windows SDK exists on the machine
  • The certificate name is SomeName and is present in the local machine maybe with a different file name
  1. Go to Start > Run
  2. Type mmc
  3. Click on File > Add/Remove Snap-in…
  4. Click the Add
  5. Click on Certificates
  6. Select Computer Account
  7. Click Finish
  8. Click Close to finish adding the Snap-in
  9. Click Ok
  10. Under Console Root, expand Certificates (Local Computer)
  11. Expand Personal
  12. Click Certificates
  13. Right click and click on All Tasks > Import
  14. Click Next
  15. Click Browse, locate the exported certificate (use *.*) and then double click on it
  16. Click Next
  17. Type the password and then click Next
  18. Select Place all certificates in the following store
  19. If Personal isn’t showing in the box under, then click Browse, select Personal and click OK
  20. Click Next
  21. Click Finish
  22. Click OK
  23. Copy the executable findprivatekey.exe to c:\
  24. Go to Start > Run type cmd
  25. Go to the C:\ prompt
  26. Execute the following command: findprivatekey.exe My LocalMachine -n “CN=SomeName” -a
  27. Copy the output of that command in Notepad
  28. Remove all line breaks if you see any
  29. Replace the {output from above} by the text from step 29 and execute the following command:  cacls “{output from above}” /E /P NETWORKSERVICE:R Example: cacls “C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys\9e7f481ca4127144bc75102dabb32ad0_c18e0de9-0e80-4436-920c-4ab1cae7939a” /E /P NETWORKSERVICE:R
  30. You’re done!

The findprivatekey.exe is available here (rename .gif to .exe)

Older Posts »