Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi all,

i want to validate my html text box without runat="server" to requiredfieldvalidator.

thanks,
krunal
Posted

It's not possible to validate a HTML control using RequiredFieldValidator. If you want to validate your HTML control client side only then you need to use JavaScript.

RequiredFieldValidator is used only for server controls.


--Amit
 
Share this answer
 
Comments
kk2014 12-Sep-12 8:05am    
hi, i have assigned my html control value to other text box which is runat="server". see below.

on .aspx page code is:
<input id="txtplace" type="text" visible="false" value="" runat="server" />
<script type="text/javascript">

function CopyVal() {
document.getElementById("txtplace").value = document.getElementById("input1").value;

return false;
}
function isValid(tab)
{
return Page_ClientValidate();
}
</script>

on code behind i am wirting code:

txtplace.Attributes.Add("onblur", "javascript:return isValid('txtplace');");

bt it doesnt work.now is there any solution?
Hi, you can validate your html text box with javascript:


HTML
<input name="tel" id="tel" type="text" size="20" maxlength="200" style="width: 200px;"  önblur="checkTelRequired(this);" /><label>*</label>
<label id="telRequired" style="display: none;">Required</label>

JavaScript
function checkRequired(whatYouTyped) {
     var txtTel = whatYouTyped.value;
     var telRequired = document.getElementById("telRequired");
     if (txtTel == "") {
         telRequired.style.display = "";
         return false;
     }
     else {
         telRequired.style.display = "none";
     }
     return true;
}
 
Share this answer
 
v3
Comments
kk2014 12-Sep-12 8:15am    
hi, in my project on form load there will be text "mandetory*" next to every label. on selection/input of text it will disappear.
 
Share this answer
 
hi,

i partially success. now the pro. is that when i click any where in webpage or select or input values t controls then my text disappears.

i want it disappear on selection on that dropdown control only.
 
Share this answer
 
v3
CLIENT SIDE VALIDATION:
XML
<label for="fname">First Name *</label>
 <input required type="text" name="fname" id="fname">

USE JQUERY/JAVASCRIPT FOR VALIDATIONS
RequiredFieldValidator IS FOR SERVER SIDE VALIDATIONS.
WITH OUT RUN@SERVER YOU CANNOT DO THAT
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900