Ternary Operator
Ternary operator used to easy way of checking condition instead of if condition using Javascript in Asp.Net C#.
? - True Condition
: - False Condition
DEMO
Ternary operator used to easy way of checking condition instead of if condition using Javascript in Asp.Net C#.
? - True Condition
: - False Condition
DEMO
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ternary Operator Using Javascript in Asp.Net </title>
<script type="text/javascript">
function ternary() {
var username = document.getElementById("txtUsername").value;
var password = document.getElementById("txtPassword").value;
var Userresult = username == "admin" ? "Username Valid" : "Username Invalid";
var Passresult = password == "admin" ? "Password Valid" : "Password Invalid";
alert(Userresult + "," + Passresult);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div >
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Username"></asp:Label>
<asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Login" OnClientClick="ternary();" />
</div>
</form>
</body>
</html>
0 comments:
Post a Comment