25 February 2009

Preventing right click in websites

var message="Sorry, Right Click is disabled.";

function click(e)
{
if (document.all)
{
if (event.button == 2)
{
alert(message);
return false;
}
}
if (document.layers)
{
if (e.which == 3)
{
alert(message);
return false;
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

12 February 2009

Filter dataset

Dataset.Tables[0].DefaultView.RowFilter = "Id not in(" + tmpItemIds + ") and Name like '%" + txtSearch.Text + "%'";

BusinessCommon.FillDataBoundControl(grvItem, Dataset.Tables[0].DefaultView);

Set cursor position Last ( TextBox )

function setCursorPosition(elementRef, cursorPosition)
{
if ( typeof elementRef == 'string' )
elementRef = document.getElementById(elementRef);

if ( elementRef != null )
{
if ( elementRef.createTextRange )
{
var textRange = elementRef.createTextRange();
textRange.move('character', cursorPosition);
textRange.select();
}
else
{
if ( elementRef.selectionStart )
{
elementRef.focus();
elementRef.setSelectionRange(cursorPosition, cursorPosition);
}
else
{
elementRef.focus();
}
}
}
}

--------------------

ScriptManager.RegisterStartupScript(this, this.GetType(), "k", "setCursorPosition('" + TextBox2.ClientID + "'," + TextBox2.Text.Length + ");", true);