Anthony Matovu
asked on
using field validator on a radio button and text box
I have two options A and B
If the user selects A he is not supposed to enter anything for the text box.
if the user selects B then it is compulsory to enter a value in the text box.
I want to control this by a field validator in asp.net 3.5
If the user selects A he is not supposed to enter anything for the text box.
if the user selects B then it is compulsory to enter a value in the text box.
I want to control this by a field validator in asp.net 3.5
ASKER
Thanks you, I am using vb.net (sorry i was not very clear)
cant i use the compare validator?
the radio button selection is mandatory
Anthony
cant i use the compare validator?
the radio button selection is mandatory
Anthony
You can solve your problem like this way.
<asp:RadioButtonList runat="server" ID="radio">
<%--Creaint Items to be display in Radio Button List--%>
<asp:ListItem Value="0">Male</asp:ListIt
<asp:ListItem Value="1">Female</asp:List
</asp:RadioButtonList>
<%--Creating RequiredFieldValidator control to validate RadioButtonList that we have created--%>
<asp:RequiredFieldValidato
Eighther you can use initialvalue property required filed validator. which is like
<asp:RequiredFieldValidato
ASKER
I want something like
if user has select option b and the text box is missing the raise the error massege
and
if user has select option a and the text box is not missing the raise the error massege
thank you
if user has select option b and the text box is missing the raise the error massege
and
if user has select option a and the text box is not missing the raise the error massege
thank you
the solution which i had given earlier is nothing to do with vb.net or c# the function is a javascript function and when the user try to click the button call that function the way which i did using the link button
using OnClientClick="return ValidateCategory();"
it is a working solution just try if not i will provide the complete code
using OnClientClick="return ValidateCategory();"
it is a working solution just try if not i will provide the complete code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and you did not specify that does the radio button selection is mandatory or not
<asp:LinkButton ID="lbnGeneral" runat="server" CssClass="leftmenu_link" OnClick="lbnGeneral_Click"
function ValidateCategory()
{
//Place your RadioButton List Id and textBox Id i just used for reference
var rbnCategories= document.getElementById ("<%= rblCategory.ClientID %>");
var rbnCategoryList= rbnCategories.getElementsB
var checkCount = false;
var j=0;
for(var i=0;i<rbnCategoryList.leng
{
j=j+1;
if(rbnCategoryList[i].chec
{
checkCount = true;
break;
}
}
if(checkCount)
{
if(j==2)
{
if(document.getElementById
{
alert("Please enter Some data into the Textbox");
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
else
{
alert("please select atleast one option");
return false;
}
}