Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

August 13, 2012

Server side script for Hiding controls




 public void hidecontrl()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script type=\"text/javascript\">\n");
            sb.Append("Sys.Application.add_load(hidebtn);\n");
            sb.Append("function hidebtn() {\n");
            sb.Append("$('input:imagebutton[id$=imgbtnAnnouncEdit]').hide();\n");
            sb.Append("$('input:imagebutton[id$=imgbtnAnnouncDelete]').hide();}\n");
            sb.Append("</script>\n");
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sb.ToString());      
        }
      

call hidecontrl(); in whichever function you need.

March 02, 2012

Change a First letter of a word to Uppercase

function changeToLowerCase(controlName)
{

document.getElementById(controlName).value = document.getElementById(controlName).value.toLowerCase();

}

//For address (if it contains numbers)function changeToLowerCase1(AddresscontrolName) {


debugger;

var address2 = "";

var address = document.getElementById(AddresscontrolName).value;

var addarray = address.split(' ');

for (var i = 0; i < addarray.length; i++) {

address2 = address2 + " " + addarray[i].toLowerCase();

}

if (address2.charAt(0) == " ") {


document.getElementById(AddresscontrolName).value = address2.trim();

}

else {


document.getElementById(AddresscontrolName).value = address2;

}

}



style="text-transform:capitalize;" onblur="this.value=this.value.substr(0, 1).toUpperCase() + this.value.substr(1);" onChange="changeToLowerCase(this.id)" MaxLength="50" onKeyUp="trimstring(this.id,this.value);"

validation for required field

function WebForm_OnSubmit() {

if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {

var txt = document.getElementById("<%= txtClinicianName.ClientID%>").value;

if (txt == "") {

document.getElementById("<%= txtClinicianName.ClientID%>").className = "error";

document.getElementById("<%= txtClinicianName.ClientID%>").focus();

}

else {


document.getElementById("<%= txtClinicianName.ClientID%>").className = "special_text_blue_white";

}

}

else {


return true;

}

}

November 28, 2011

Expiry date validation






function ExpDateChk(sender, args)
{

       
var Today = new Date();

var expDate = new Date(document.getElementById("<%# txtLicenceExpiryDate.ClientID %>").value)

if (Today.setDate(Today.getDate()+6) > expDate) {

args.IsValid = false;

}

else {

args.IsValid = true;

}

}

Back Button in JS



window.history.go(-1);
window.location.reload();
}

window.history.go(-1);
}
}
function GoBack() {if ($.browser.msie) {else {

Validate dropdown

function ValidateddlState(sender, args)
 {
Var str = new String();

str = args.Value;

     


if (str == "0") {

args.IsValid =
false;

}



else {

args.IsValid =
true;

}

}

November 25, 2011

Zipcode validation


function Patientzipcode(sender, args)
 {


var zipcode = document.getElementById('<%= txtZipCode.ClientID%>').value;
if (zipcode == "00000"
{
document.getElementById('<%= CustmZipcode.ClientID%>').innerHTML = "Please enter valid zipcode";
return args.IsValid = false;
}
else


{
return args.IsValid = true;
}
}

November 16, 2011

Phone no validation

function ValidatetxtPhone(sender, args)
{

document.getElementById('<%# CustomPhoneNumber.ClientID %>').innerHTML = "";

var txt1 = document.getElementById('<%# txtPhone1.ClientID %>').value;

var txt2 = document.getElementById('<%# txtPhone2.ClientID %>').value;

var txt3 = document.getElementById('<%# txtPhone3.ClientID %>').value;

if ((txt1 == "000") && (txt2 == "000") && (txt3 == "0000")) {

document.getElementById('<%# CustomPhoneNumber.ClientID %>').innerHTML = "Please enter valid phone number";

return args.IsValid = false;

}

else if ((txt1 != "") && (txt1 == 3)) {


if ((txt2 != "") && (txt2 == 3)) {

if ((txt3 != "") && (txt3 == 4)) {

return args.IsValid = true;

}

}

}

else if ((txt1 == "") && (txt2 == "") && (txt3 == "")) {


document.getElementById('<%# CustomPhoneNumber.ClientID %>').innerHTML = "Please enter phone number(### ### ####)";

return args.IsValid = false;

}

else if ((txt1.length < 3) || (txt2.length < 3) || (txt3.length < 4)) {


document.getElementById('<%# CustomPhoneNumber.ClientID %>').innerHTML = "Please enter valid phone number";

return args.IsValid = false;

}

else {


return args.IsValid = true;

}

}

Validation for required field

function WebForm_OnSubmit()
 {

if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {

var txt = document.getElementById("<%= txtClinicianName.ClientID%>").value;

if (txt == "") {

document.getElementById("<%= txtClinicianName.ClientID%>").className = "error";

document.getElementById("<%= txtClinicianName.ClientID%>").focus();

}

else {

document.getElementById("<%= txtClinicianName.ClientID%>").className = "special_text_blue_white";

}

}

else {

return true;

}

}

dob validation

function validateDOB(sender, args)
{

var startDate = new Date(document.getElementById('<%= txtDateOfBirth.ClientID %>').value)

var todaydate = new Date();

if (startDate >= todaydate)
 {

args.IsValid = false;

}

else
 {

args.IsValid = true;

}

}

Date validation

<asp:TextBox ID="txtVisitDate" TabIndex="1" Width="100px" MaxLength="10" runat="server"

CssClass="special_text_brown"></asp:TextBox>

<asp:RegularExpressionValidator runat="server" ID="regVisitDate" ControlToValidate="txtVisitDate"

ErrorMessage="Please enter valid date" Display="Dynamic" ValidationExpression="(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))" />

<cc1:FilteredTextBoxExtender ID="ftxtVisitDate" runat="server" TargetControlID="txtVisitDate"

FilterType="Custom" InvalidChars="A-Z, a-z" ValidChars="/,1,2,3,4,5,6,7,8,9,0">

</cc1:FilteredTextBoxExtender>

<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="false"

ShowSummary="false" />

<cc1:CalendarExtender ID="calextVisitdate" Format="MM/dd/yyyy" TargetControlID="txtVisitDate"

runat="server">

</cc1:CalendarExtender>

Javascript time validation

//TIME VALIDATION

function TimeValidation(sender, args) {

var date = ('<%= (System.DateTime.Now).ToString()%>');

var F1, F2, M1, M2;

var TimeIn = $('#<%= txtTimeIn1.ClientID %>').val();

var TimeOut = $('#<%= txtTimeOut1.ClientID %>').val();

if ((TimeIn == "") && (TimeOut == "")) {

return args.IsValid = true;

}

var Time1 = TimeIn.split(":");

var Time2 = TimeOut.split(":");

F1 = Time1[0];

M1 = Time1[1];

F2 = Time2[0];

M2 = Time2[1];

if (TimeIn != "") {

var Min1 = M1.split(" ");

if ((F1 > 12) || (Min1[0] >= 60)) {

$('#<%= CustomTime.ClientID %>').text("Please enter valid Time in");

return args.IsValid = false;

}

}

if (TimeOut != "") {

var Min2 = M2.split(" ");

if ((F2 > 12) || (Min2[0] >= 60)) {

$('#<%= CustomTime.ClientID %>').text("Please enter valid Time out");

return args.IsValid = false;

}

}

if (((TimeIn == "00:00 AM") || (TimeIn == "00:00 PM") || (TimeIn == "")) && (TimeOut != "")) {

$('#<%= CustomTime.ClientID %>').text("Please enter valid Time out");

return args.IsValid = false;

}

if (((TimeOut == "00:00 AM") || (TimeOut == "00:00 PM") || (TimeOut == "")) && (TimeIn != "")) {

$('#<%= CustomTime.ClientID %>').text("Please enter valid Time out");

return args.IsValid = false;

}

if ((TimeIn != "") && (TimeOut != "")) {

var splitdate = date.split(" ");

var jdt1 = Date.parse(splitdate[0] + ' ' + $('#<%= txtTimeIn1.ClientID %>').val());

var jdt2 = Date.parse(splitdate[0] + ' ' + $('#<%= txtTimeOut1.ClientID %>').val());

if (jdt1 >= jdt2) {

$('#<%= CustomTime.ClientID %>').text("Time out should be greater than Time in");

return args.IsValid = false;

}

}

else {

$('#<%= CustomTime.ClientID %>').text("");

return args.IsValid = true;

}

}

//TimeValidation1

function TimeValidation1(sender, args) {

var date = ('<%= (System.DateTime.Now).ToString()%>');

var F1, F2, M1, M2;

var TimeIn2 = $('#<%= txtTimeIn2.ClientID %>').val();

var TimeOut2 = $('#<%= txtTimeOut2.ClientID %>').val();

if ((TimeIn2 == "") && (TimeOut2 == "")) {

return args.IsValid = true;

}

var Time1 = TimeIn2.split(":");

var Time2 = TimeOut2.split(":");

F1 = Time1[0];

M1 = Time1[1];

F2 = Time2[0];

M2 = Time2[1];

if (TimeIn2 != "") {

var Min1 = M1.split(" ");

if ((F1 > 12) || (Min1[0] >= 60)) {

$('#<%= CustomTime1.ClientID %>').text("Please enter valid Time in");

return args.IsValid = false;

}

}

if (TimeOut2 != "") {

var Min2 = M2.split(" ");

if ((F2 > 12) || (Min2[0] >= 60)) {

$('#<%= CustomTime1.ClientID %>').text("Please enter valid Time out");

return args.IsValid = false;

}

}

if (((TimeIn2 == "00:00 AM") || (TimeIn2 == "00:00 PM") || (TimeIn2 == "")) && (TimeOut2 != "")) {

$('#<%= CustomTime1.ClientID %>').text("Please enter valid Time in");

return args.IsValid = false;

}

if (((TimeOut2 == "00:00 AM") || (TimeOut2 == "00:00 PM") || (TimeOut2 == "")) && (TimeIn2 != "")) {

$('#<%= CustomTime1.ClientID %>').text("Please enter valid Time out");

return args.IsValid = false;

}

if ((TimeIn2 != "") && (TimeOut2 != "")) {

var splitdate = date.split(" ");

var jdt1 = Date.parse(splitdate[0] + ' ' + $('#<%= txtTimeIn2.ClientID %>').val());

var jdt2 = Date.parse(splitdate[0] + ' ' + $('#<%= txtTimeOut2.ClientID %>').val());

if (jdt1 >= jdt2) {

$('#<%= CustomTime1.ClientID %>').text("Time out shoud be greater than Time in");

return args.IsValid = false;

}

}

else {

$('#<%= CustomTime1.ClientID %>').text("");

return args.IsValid = true;

}

}


<asp:TextBox ID="txtTimeIn2" TabIndex="5" Width="60px" CssClass="special_text_brown"

runat="server"> </asp:TextBox>

<cc1:MaskedEditExtender ID="mskEditExtTimeIn2" runat="server" MaskType="Time" UserTimeFormat="None"

TargetControlID="txtTimeIn2" Mask="99:99" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus"

OnInvalidCssClass="MaskedEditError" InputDirection="LeftToRight" AutoComplete="true"

ErrorTooltipEnabled="True" AcceptAMPM="true">

</cc1:MaskedEditExtender>

<asp:CustomValidator ID="CustomTime1" runat="server" SetFocusOnError="true" ClientValidationFunction="TimeValidation1" Display="Dynamic" ></asp:CustomValidator>