I have one text box in my grid and need to set validation like should allow numbers upto
3 digits only
validation should be done from code behind (grid row databound)
i have javascript its working fine .but i need same js in row data bound
function validate()
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var intrval = document.getElementById('ctl00_Mdi_grdabc_txtInterval');
//comparing pressed keycodes
if (!(keycode==8 || keycode==46)&&(keycode < 48 || keycode > 57)) {
alert("Please Enter Digits only");
return false;
}
else
{
//Condition to check textbox contains 3 numbers or not
if (intrval.value.length < 3)
{
return true;
}
else
{
alert("Interval Should not be greater than 3 digits");
return false;
}
}
}
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Abhishek KumarPosted Sep 15, 2014, 12:24 PM
Seems some issue with the paste.
protected void gvPlanMaintenance_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
TextBox txt= (TextBox)e.Row.Cells[0].FindControl("txtInterval");
if (txt != null)
{
btnTest.Attributes.Add("onkeypress", "javascript:return Validate();");
}
}
Abhishek
Abhishek KumarPosted Sep 16, 2014, 4:41 AM
Cheers
Abhishek
vamsidhar kotipalliPosted Sep 16, 2014, 2:54 AM
vamsidhar kotipalliPosted Sep 16, 2014, 2:53 AM
Abhishek KumarPosted Sep 15, 2014, 12:23 PM