在网格中的textchange事件中验证 [英] validate in textchange event in the grid

查看:69
本文介绍了在网格中的textchange事件中验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function isValidDate(sText) {
    var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
    return reDate.test(sText);
}
function validateDate(id) {
    //debugger;
    if (document.getElementById(id).value != '') {
        var oInput1 = document.getElementById(id);
        if (isValidDate(oInput1.value)) {
            //By Dileep [03Jan11] to clear colors after correct validation
            document.getElementById(id).style.backgroundColor = "white";
            document.getElementById(id).style.color = "black";
            //End Dileep
        }
        else {
            //By Dileep [03Jan11] to not alert the end user
            // alert("Enter in DD/MM/YYYY");
            document.getElementById(id).value = "";
            //document.getElementById(id).focus();
            //End Dileep
            document.getElementById(id).style.backgroundColor = "#fba09d";
        }
    }
    else {
        //By Dileep [03Jan11] to not allow blank date
        //document.getElementById(id).focus();
        document.getElementById(id).style.backgroundColor = "#fba09d";
        //end dileep
    }
}
//By Dileep Kumar 01Feb2011  -- To Restrict the user to feed Date
function checkDate(str, id) {
    // debugger;
    if (parseInt(document.getElementById(id).value.length) < 10) {
        // ValidInput(str);
        var KeyID = event.keyCode;
        var ch = String.fromCharCode(KeyID);
        if (str.indexOf(ch) > -1)
            return true;
        else
            return false;
    }
    else {
        return false;
    }
}



C#代码------------------------------------------------ -----



C# Code-----------------------------------------------------

protected void NameofFormTxt_TextChanged(object sender, EventArgs e)
        {
           
            int i=Convert.ToInt32(ViewState["RowInd"].ToString());
            TextBox ValTextbox = (TextBox)BindTextBoxGv.Rows[i].Cells[1].FindControl("NameofFormTxt");
            if (i == 0)
            {
                ValTextbox.Attributes.Add("onblur", "return validateDate('ctl00$ctl00$ParentContentPlaceHolder$MasterOperationsContentPlaceHolder$BindTextBoxGv$ctl02$NameofFormTxt');");
            }
        }


-------------------------------------------------- -
我的问题是我想以以下方式从文本更改事件中调用上述Javascript,但是我失败了.还有其他方法可以调用Javascript吗?


我也尝试过以下方式


---------------------------------------------------
My problem is I want to call the above Javascript from the text change event in the following manner but I fail. Is there any other way to call the Javascript?


I also tried in the following way

//----------------------
1.if (i == 0)
            {
                ValTextbox.Attributes.Add("onblur", "return validateDate(this.id);");

//----------------

2.if (i == 0)
            {
                ValTextbox.Attributes.Add("onblur", "return validateDate(<%=NameofFormTxt.ClientID%>);");
}



---------------------------
请帮助我



---------------------------
Please help me

推荐答案

ctl00


ParentContentPlaceHolder
ParentContentPlaceHolder


MasterOperationsContentPlaceHolder
MasterOperationsContentPlaceHolder


这篇关于在网格中的textchange事件中验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆