Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Mobile No:
<asp:textbox id="txtmobile" run="ser" /><br />
If you don't have mobile <a önclick="showLandline()"> Click here </a>
<div id="hiddenLandline" style="display:none">
  <asp:textbox" id="txtlandline" run="ser" />
</div>
<br />
<asp:button id="btnSubmit" text="Validate" run="ser"/>

<script type="text/javascript">
  function showLandline()
  {
    document.getElementById('hiddenLandline').style.display="block";
  }
</script>

When I click the Validate button, the required field validator validate only mobile no but if landline text box has display property block than it will checks that both or either textbox don't be empty.
If landline textbox display property is none than required validator don't validate this field.
Posted
Updated 23-Sep-11 18:53pm
v3
Comments
rkthiyagarajan 24-Sep-11 0:26am    
If you set target field for land line textbox?

1 solution

Try this ..

<pre lang="xml">&lt;script type=&quot;text/javascript&quot;&gt;
function showLandline() {
document.getElementById('hiddenLandline').style.display = &quot;block&quot;;
document.getElementById('divMob').style.display = &quot;none&quot;;
}
&lt;/script&gt;</pre>



&lt;body&gt;
&lt;form id="form1" runat="server"&gt;
<div>

<asp:textbox id="txtmobile" runat="server" xmlns:asp="#unknown" /><br />
<div id="divMob">
<asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server" errormessage="mob" xmlns:asp="#unknown">
ControlToValidate="txtmobile"&gt;</asp:requiredfieldvalidator>
</div>
If you don't have mobile <a onclick="showLandline()">Click here </a>
<div id="hiddenLandline" style="display: none">
<asp:textbox id="txtlandline" runat="server" xmlns:asp="#unknown" />
<asp:requiredfieldvalidator id="RequiredFieldValidator2" runat="server" errormessage="land" xmlns:asp="#unknown">
ControlToValidate="txtlandline"&gt;</asp:requiredfieldvalidator>
</div>
<br />
<asp:button id="btnSubmit" text="Validate" runat="server" xmlns:asp="#unknown" />
</div>
&lt;/form&gt;
&lt;/body&gt;<pre lang="text"></pre>
 
Share this answer
 
v2

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