how to implement switch block in asp.net

This code shows how to implement switch block in asp.net


<%@ Page Language="C#" %>
<script runat="server">

void page_Load()
{
if(Page.IsPostBack)
{
switch (txtIn.Text)
{
case "yes":
lblOut.Text= "Details will be sent.";
break;

case "YES":
lblOut.Text= "Details will be sent.";
break;

case "Yes":
lblOut.Text= "Details will be sent.";
break;

case "no":
lblOut.Text= "We will not contact you.";
break;

case "NO":
lblOut.Text= "We will not contact you.";
break;

case "No":
lblOut.Text= "We will not contact you.";
break;

default:
lblOut.Text = "Your answer " + txtIn.Text + " is not recognized.";
break;
} //end switch (txtIn.Text)

} //end if(Page.IsPostBack)

} //end page_Load()

</script>
<html>
<head>
</head>
<body>
<form runat="server">
Please type yes or no:
<asp:TextBox runat="server" ID="txtIn"/><br/>
<asp:Button runat="server" Text="Submit"/><br/>
<asp:Label runat="server" ID="lblOut"/><br/>
</form>
</body>
</html>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: