can we use javascript and ajax on same control in asp.net

Posted by Shanky11 under ASP.NET AJAX on 2/14/2013 | Points: 10 | Views : 1931 | Status : [Member] | Replies : 1
can we use javascript and ajax on same control?????????????????
i have a form inside that 4 txtfield are there i used required field validator and ajax validator extender
but this is only for user cant move ahead unless and until he fill all the details
now the problem is that if user enter the number in name field and character in mobile no filed how can i validate that
if i m using jvascript then ajax is not wrking
how an i coe across this problem



Please provide solution for this not web link




Responses

Posted by: lakhansin-22735 on: 7/8/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,

I'm not very clear about your problem, but as per my understanding you can use CustomValidator, using this validator control you can achieve both JavaScript and Ajax functionality.
see the below code at ASPX page
<asp:TextBox ID="txtLicenseNo" runat="server" MaxLength="20" Font-Bold="true"></asp:TextBox><br />

<asp:RequiredFieldValidator ID="rfvLicenseNo" runat="server" ControlToValidate="txtLicenseNo"
ErrorMessage="Required" Display="Dynamic" SetFocusOnError="true" ValidationGroup="vgLicense"
EnableClientScript="true"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="cmvalLicneseNumber" SetFocusOnError="true" ValidationGroup="vgLicense"
ControlToValidate="txtLicenseNo" ClientValidationFunction="ValLicenseLength"
Display="Static" runat="server" ErrorMessage="Invalid"></asp:CustomValidator>

<script>
function ValLicenseLength(sender, e) {
var LicenseLength = (document.getElementById('<%=txtLicenseNo.ClientID %>').value).length;
e.IsValid = true;
if (LicenseLength < 4) {
e.IsValid = false;
}
else {
e.IsValid = true;
}
}
</script>

Please, let me know something more, so that I will help you.

Thanks


Lakhan Singh
Tech Lead
BeyondKey System Pvt. Ltd.
Indore, M.P.
India

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response