Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please give me the proper client side code for how we can declare if and else condition. Not in a code file i am just use in a asp.net source code.
Thanks in advance

EDIT
-------------------------
Copied from Comment


actually i don't want this. I am try to hide some controls if condition is true in asp.net source code not in a code file.
Posted
Updated 10-May-11 8:33am
v3
Comments
Mahendra.p25 10-May-11 6:51am    
what do you want???

Sometimes I feel it difficult to control myself after reading these type of questions.

Anyways, here it is: http://www.w3schools.com/js/js_if_else.asp[^]
 
Share this answer
 
Comments
rahul dev123 10-May-11 6:56am    
actually i don't want this. I am try to hide some controls if condition is true in asp.net source code not in a code file.
Hemant__Sharma 10-May-11 7:17am    
Your question title and its detail must show what you "want".
BobJanova 10-May-11 10:00am    
You said 'client side'. Client side for ASP.net is in the browser, i.e. Javascript. Also, 'ASP.net source code' is a 'code file'. Perhaps you should actually learn something about technologies before trying to use them.
BobJanova 10-May-11 9:59am    
lol, well played
Consider you have 3 Divs & Buttons for displaying message based on your condition
<div id="divMessage1">Message1</div>
<div id="divMessage2">Message2</div>
<div id="divMessage3">Message3</div>
<input type="button" value="Button1" onclick="fnDisplayMessage(1)" />
<input type="button" value="Button2" onclick="fnDisplayMessage(2)" />
<input type="button" value="Button3" onclick="fnDisplayMessage(3)" />

Here javascript for Show/Hide Divs using if else condition
<script type="text/javascript">
function fnDisplayMessage(MessageID){
    if (MessageID == 1){
        document.getElementById("divMessage1").style.display="block";
        document.getElementById("divMessage2").style.display="none";
        document.getElementById("divMessage3").style.display="none";
    } else if (MessageID == 2){
        document.getElementById("divMessage1").style.display="none";
        document.getElementById("divMessage2").style.display="block";
        document.getElementById("divMessage3").style.display="none";
    } else if (MessageID == 3){
        document.getElementById("divMessage1").style.display="none";
        document.getElementById("divMessage2").style.display="none";
        document.getElementById("divMessage3").style.display="block";
}
</script>

Hope it will help you. BTW next time please include all details completely & code(which you have tried) in your question because it will help you to get solution quickly.
 
Share this answer
 
The below code demonstrates hiding or setting visibility of TextBox or button based on certain criteria.


[If you have a drop down list and on select of first index if you want to hide Submit Button and on select of second index you want to hide textbox. Then use the beolw code]



function ToConfirm() {

var selected = document.getElementById('&lt;%=ddlMailSmsType.ClientID%&gt;').selectedIndex;

if(selected==0)
{
document.getElementById('&lt;%=txtboxNum.ClientID%&gt;').style.display = "block";
}
else
{
document.getElementById('&lt;%=btnSubmit.ClientID%&gt;').style.display = "none";
}


Call the Javascript function on click of any event or as per your requirment.

Hope this will help you.

Thanks and regards
Praveen
 
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