Asp.Net Disable Copy Paste in TextBox

Asp.Net Disable Copy Paste in TextBox

Use this Javascript to Disable Copy Paste From Keyboard Ctrl+C , Ctrl+V and from Mouse

<script type=”text/javascript” language=”javascript”>
function noCopyMouse(e) {
var isRight = (e.button) ? (e.button == 2) : (e.which == 3);

if(isRight) {

return false;
}
return true;
}

function noCopyKey(e) {
var forbiddenKeys = new Array(‘c’,’x’,’v’);
var keyCode = (e.keyCode) ? e.keyCode : e.which;
var isCtrl;

if(window.event)
isCtrl = e.ctrlKey
else
isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;

if(isCtrl) {
for(i = 0; i < forbiddenKeys.length; i++) {
if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
//  alert(‘You are prompted to type this twice for a reason!’);
return false;
}
}
}
return true;
}

</script>

Call This Javascript From Code

TextBox1.Attributes.Add(“onmousedown”, “return noCopyMouse(event);”);
TextBox1.Attributes.Add(“onkeydown”, “return noCopyKey(event);”);
TextBox1.Attributes.Add(“oncontextmenu”, “return false;”);

Advertisement

Asp.net Image Control Not Refresh with same name problem

Solve Asp.net Image control which is not refresh with the same name

I got This Article From http://forums.asp.net/t/1176582.aspx

To Refresh Or We can see Display Image in Asp.Net Image Control with Same name that create a problem
To solve above problem we can attach  unique code with image name

printImage.ImageUrl = “~\\sessions\\sd_” + Session.SessionID + \\printMAD.bmp + “?” + RandomNumber.ToString();

Where RandomNumber is some randomly generated number, or you could also replace RandomNumber.ToString() with System.Guid.NewGuid().ToString() which is also unique.

Asp.net Custom Validator For File Upload Control

<script language =”javascript” type=”text/javascript”>
function Trim(input)
{
var lre = /^\s*/;
var rre = /\s*$/;
input = input.replace(lre, “”);
input = input.replace(rre, “”);
return input;
}

// filter the files before Uploading for text file only
function CheckForTestFile(source, args)
{
var file = document.getElementById(‘<%=fuSelectPhoto.ClientID%>’);
var fileName=file.value;
//Checking for file browsed or not
if (Trim(fileName) ==” )
{
alert(“Please Select a File to Upload!!!”);
file.focus();
args.IsValid = false;
}

//Setting the extension array for diff. type of text files
var extArray = new Array(“.jpg”, “.jpeg”, “.gif”);

//getting the file name
while (fileName.indexOf(“\\”) != -1)
fileName = fileName.slice(fileName.indexOf(“\\”) + 1);

//Getting the file extension
var ext = fileName.slice(fileName.indexOf(“.”)).toLowerCase();

//matching extension with our given extensions.
for (var i = 0; i < extArray.length; i++)
{
if (extArray[i] == ext)
{
return true;
}
}
alert(“Please Only Upload Image File:  ”
+ (extArray.join(”  “)) + “\nPlease Select a New ”
+ “File to Upload and Submit again.”);
file.focus();
args.IsValid = false;
}
</script>

Call This Javascript Funcation For Custom  Validator Like

<asp:CustomValidator ID=”CustomValidator1″ runat=”server”  ClientValidationFunction=”CheckForTestFile”
ErrorMessage=”Please Upload Image”></asp:CustomValidator>

Asp.Net File upload Validation From Javascript and Validator Control

Asp.Net File Upload Client Side Validation  and

<script language=”javascript” type=”text/javascript”>

function Trim(input)
{
var lre = /^\s*/;
var rre = /\s*$/;
input = input.replace(lre, “”);
input = input.replace(rre, “”);
return input;
}

// filter the files before Uploading for text file only
function CheckForTestFile()
{
var file = document.getElementById(‘<%=fuSelectPhoto.ClientID%>’);
var fileName=file.value;
//Checking for file browsed or not
if (Trim(fileName) ==” )
{
alert(“Please Select a File to Upload!!!”);
file.focus();
return false;
}

//Setting the extension array for diff. type of text files
var extArray = new Array(“.jpg”, “.jpeg”, “.gif”);

//getting the file name
while (fileName.indexOf(“\\”) != -1)
fileName = fileName.slice(fileName.indexOf(“\\”) + 1);

//Getting the file extension
var ext = fileName.slice(fileName.indexOf(“.”)).toLowerCase();

//matching extension with our given extensions.
for (var i = 0; i < extArray.length; i++)
{
if (extArray[i] == ext)
{
return true;
}
}
alert(“Please Only Upload Image File:  ”
+ (extArray.join(”  “)) + “\nPlease Select a New ”
+ “File to Upload and Submit again.”);
file.focus();
return false;
}

</script>

Call This Javascript function On Button OnClientClick Event

OnClientClick =”return CheckForTestFile();”

ASP.Net DateFormat dd/MM/yyyy

Asp.Net Assign Date In dd/MM/yyyy  Format
From Databse to Application Page

txtMembershipDate.Text = dsMembership.Tables[0].Rows[0][“MembershipDate”].ToString() == “” ? “” : Convert.ToDateTime(dsMembership.Tables[0].Rows[0][“MembershipDate”]).ToString(“dd/MM/yyyy”); ;

From Code to Sql Server
Date Fromat dd/MM/yyy to MM/dd/yyyy

DateTime dtMemberShipdate = DateTime.ParseExact(txtMembershipDate.Text , “dd/MM/yyyy“, System.Globalization.CultureInfo.CurrentCulture);
objMembership.MemberShipDate = dtMemberShipdate.ToString();