Click here to Skip to main content
15,886,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,

am working on asp.net project using c#, Sqlserver 2005 database.

I need validation for textboxes.

on my webpage i have 6 textboxes, i gave validations for this, its fine.

I need a validation for textbox, that user has the choice to enter in textboxes.

my textboxes are

ModelNo - TxtModelNo
SerailNo - TxtSerailNo
AssignedTo - TxtAssignedTo
Location - TxtLocation
CompanyTagNo - TxtCompanyTagNo
EmployeeTagNo - TxtEmployeeTagNo

from these textboxes, first 4 textboxes are required compulsory, and the last two are under choice.

These two textboxes are under choice

CompanyTagNo - TxtCompanyTagNo
EmployeeTagNo - TxtEmployeeTagNo

the user can enter in both textboxes OR
he can enter in one also OR
he can enter in both also
BUT both should not be empty.

Please help,
Thanks
Posted
Comments
OriginalGriff 21-Apr-13 5:50am    
And?
What is your problem?
What have you tried?
Where are you stuck?
Ubaid ur Rahman IT 21-Apr-13 6:38am    
I want to use one required field validator for two textboxes inside gridview footer textboxes.
please help OriginalGriff..........

1 solution

U have to use CustomValidator control with javascript fuction for validation .Try following link ...and for other required textbox use RequiredFieldValidator
http://forums.asp.net/post/4001929.aspx[^]
 
Share this answer
 
v2
Comments
Ubaid ur Rahman IT 21-Apr-13 6:30am    
These textboxes are in gridview footer.

please can u help me how to do this.

thanks.
Pallavi Waikar 21-Apr-13 8:20am    
refer this link http://www.codeproject.com/Questions/65550/Access-Gridview-Footer-cell-via-Javascript...when u browse ur page view page source get id of TxtCompanyTagNo and TxtEmployeeTagNo.. and place in below code at place of gvEmp_ctl06_TxtEmployeeTagNo and gvEmp_ctl06_TxtCompanyTagNo

<asp:TextBox ID="TxtCompanyTagNo" runat="server">
<asp:TextBox ID="TxtEmployeeTagNo" runat="server">
<asp:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="CompanyTagNo or EmployeeTagNo Required"
Display="Dynamic"
ClientValidationFunction="CompanyTagOrEmployeeTag()" />
<script type="text/javascript">
function CompanyTagOrEmployeeTag()
{
var text=document.getElementById("gvEmp_ctl06_TxtEmployeeTagNo");
var text2=document.getElementById("gvEmp_ctl06_TxtCompanyTagNo");
if (text.value =="" && text2.value == "" )
{
alert('CompanyTagNo or EmployeeTagNo Required');
return false;
}
else
{

return true;
}
}
</script>
i think it should work
Ubaid ur Rahman IT 22-Apr-13 2:37am    
Sorry boss, this doesn't work
Ubaid ur Rahman IT 22-Apr-13 2:49am    
hello, can anybody help me regarding this problem.

Thanks.
Pallavi Waikar 22-Apr-13 3:45am    
i am trying to tell u that when u run this page of gridview all control id of girdview r change ,that's why run page view it's page source get there id and use it...if both textbox are empty then it is showing alert...try once

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