Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Front]
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- <style>
- .none{background:#ff0000}
- .success{background:#00ff21}
- .btn{
- display:block;
- margin:0;
- padding:0;
- width:100%;
- }
- .col-c{
- width:100px;
- }
- </style>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:ScriptManager ID="sc1" runat="server"></asp:ScriptManager>
- <div>
- <asp:UpdatePanel ID="upnl" runat="server" UpdateMode="Always">
- <ContentTemplate>
- <table style="border-collapse:collapse;" border="1">
- <tr>
- <td class="col-c"><asp:TextBox ID="tx1" runat="server" Text="0" AutoPostBack="true" OnTextChanged="tx1_TextChanged"></asp:TextBox></td>
- <td class="col-c"><asp:Button ID="bt1" runat="server" OnClick="bt1_Click" CssClass="btn" /></td>
- <td> </td>
- <td class="col-c"><asp:TextBox ID="tx2" runat="server" Text="0" AutoPostBack="true" OnTextChanged="tx1_TextChanged"></asp:TextBox></td>
- <td class="col-c"><asp:Button ID="bt2" runat="server" OnClick="bt2_Click" CssClass="btn" /></td>
- </tr>
- <tr>
- <td colspan="2"> </td>
- <td style="width:50px">
- <asp:PlaceHolder ID="ph1" runat="server" />
- </td>
- <td colspan="2"> </td>
- </tr>
- <tr>
- <td><asp:TextBox ID="tx3" runat="server" Text="0" AutoPostBack="true" OnTextChanged="tx1_TextChanged"></asp:TextBox></td>
- <td><asp:Button ID="bt3" runat="server" OnClick="bt3_Click" CssClass="btn" /></td>
- <td> </td>
- <td><asp:TextBox ID="tx4" runat="server" Text="0" AutoPostBack="true" OnTextChanged="tx1_TextChanged"></asp:TextBox></td>
- <td><asp:Button ID="bt4" runat="server" OnClick="bt4_Click" CssClass="btn" /></td>
- </tr>
- <tr>
- <td colspan="5">
- <asp:TextBox ID="result" runat="server" TextMode="MultiLine" Width="100%" Height="30px" style="resize:none;display:block" />
- </td>
- </tr>
- <tr>
- <td colspan="5"><asp:Button ID="clear" runat="server" Text="clear" OnClick="clear_Click" CssClass="btn" /></td>
- </tr>
- </table>
- </ContentTemplate>
- </asp:UpdatePanel>
- </div>
- </form>
- </body>
- </html>
- [C# Code-Behind]
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- }
- protected void bt1_Click(object sender, EventArgs e)
- {
- tx1.Text = check_result(Convert.ToInt32(tx1.Text) + 1);
- tx2.Text = check_result(Convert.ToInt32(tx2.Text) + 1);
- tx3.Text = check_result(Convert.ToInt32(tx3.Text) + 1);
- result.Text = result.Text + "(1)";
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- protected void bt2_Click(object sender, EventArgs e)
- {
- tx1.Text = check_result(Convert.ToInt32(tx1.Text) + 1);
- tx2.Text = check_result(Convert.ToInt32(tx2.Text) + 1);
- tx4.Text = check_result(Convert.ToInt32(tx4.Text) + 1);
- result.Text = result.Text + "(2)";
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- protected void bt3_Click(object sender, EventArgs e)
- {
- tx1.Text = check_result(Convert.ToInt32(tx1.Text) + 1);
- tx3.Text = check_result(Convert.ToInt32(tx3.Text) + 1);
- tx4.Text = check_result(Convert.ToInt32(tx4.Text) + 1);
- result.Text = result.Text + "(3)";
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- protected void bt4_Click(object sender, EventArgs e)
- {
- tx2.Text = check_result(Convert.ToInt32(tx2.Text) + 1);
- tx3.Text = check_result(Convert.ToInt32(tx3.Text) + 1);
- tx4.Text = check_result(Convert.ToInt32(tx4.Text) + 1);
- result.Text = result.Text + "(4)";
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- private void result_show(int n1, int n2, int n3, int n4)
- {
- ph1.Controls.Clear();
- if(n1 == 0)
- {
- if(n2 == 0)
- {
- if(n3 == 0)
- {
- if (n4 == 0)
- {
- ph1.Controls.Add(new Literal { Text = "<div class='success'> </div>" });
- }
- else
- {
- ph1.Controls.Add(new Literal { Text = "<div class='none'> </div>" });
- }
- }
- else
- {
- ph1.Controls.Add(new Literal { Text = "<div class='none'> </div>" });
- }
- }
- else
- {
- ph1.Controls.Add(new Literal { Text = "<div class='none'> </div>" });
- }
- }
- else
- {
- ph1.Controls.Add(new Literal { Text = "<div class='none'> </div>" });
- }
- }
- private string check_result(int num_sample)
- {
- int result = 0;
- if(num_sample== 4)
- {
- result = 0;
- }
- else
- {
- result = num_sample;
- }
- return result.ToString();
- }
- protected void clear_Click(object sender, EventArgs e)
- {
- tx1.Text = "0";
- tx2.Text = "0";
- tx3.Text = "0";
- tx4.Text = "0";
- result.Text = string.Empty;
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
- protected void tx1_TextChanged(object sender, EventArgs e)
- {
- result_show(Convert.ToInt32(tx1.Text), Convert.ToInt32(tx2.Text), Convert.ToInt32(tx3.Text), Convert.ToInt32(tx4.Text));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement