Wednesday, 16 April 2014

Show msg. after selecting color In Check Box


Write a program to display message after selecting color as per Check Box list.

********HTML Code***************
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="margin-left:30px; height: 236px; color: #008000;">
   
        <br />
        Select Your favourite Color:<br />
        <br />
        <asp:CheckBox ID="CheckBox1" runat="server" text="Blue" ForeColor="Blue"/>
        <asp:CheckBox ID="CheckBox2" runat="server" text="red" ForeColor="Red"/>
   
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Show" onclick="Button1_Click1" />
   
    &nbsp;&nbsp;&nbsp;
        <asp:Label ID="Label1" runat="server" ForeColor="#003366" Text="Label"></asp:Label>
   
    </div>
    </form>
</body>
</html>


********C# Code***************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class display_message_after_selecting_color_as_per_Check_Box : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
       protected void Button1_Click1(object sender, EventArgs e)
    {
        Label1.Text = "Ok! your favourite color is/are ";
        string color = "";
        if (CheckBox1.Checked)
            {
            // Response.Write("<font color='blue'>Blue</font>");
            Label1.Text += "<font color='blue'> Blue </font>";
            color += " Blue ";
            }

           if (CheckBox2.Checked)
            {
            //Response.Write("<font color='red'>Red</font>");
            Label1.Text += "<font color='red'> Red </font>";
            color += " Red ";
             }
            Response.Write("<script>alert('your favourite color is/are" + color + "')</script>");
            }
    }

No comments:

Post a Comment