[我的ASP.net学习历程]sender对象

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 bgu 的 blog

<%@ page language="c#" debug="true" %>
<script runat="server">
 
    void calc(object sender, eventargs e)
    {
        double answer;
        button pressedbutton = (button)sender;
        switch (pressedbutton.id)
        {
            case "btnadd":
                answer = convert.todouble(txtinput1.text) +
                         convert.todouble(txtinput2.text);
                lblanswer.text = answer.tostring();
                break;
            case "btnsubtract":
                answer = convert.todouble(txtinput1.text) -
                         convert.todouble(txtinput2.text);
                lblanswer.text = answer.tostring();
                break;
            case "btnmultiply":
                answer = convert.todouble(txtinput1.text) *
                         convert.todouble(txtinput2.text);
                lblanswer.text = answer.tostring();
                break;
            case "btndivide":
                answer = convert.todouble(txtinput1.text) /
                         convert.todouble(txtinput2.text);
                lblanswer.text = answer.tostring();
                break;
        }
        pressedbutton.backcolor = system.drawing.color.yellow;
    }

</script>
<html>
<head>
    <title>chapter 6 - calculator example v2</title>
</head>
<body>
    <form runat="server">
        <h2>calculator version 2
        </h2>
        <asp:textbox id="txtinput1" runat="server"></asp:textbox>
        <asp:button id="btnadd" onclick="calc" runat="server" text=" + "></asp:button>
        <asp:button id="btnsubtract" onclick="calc" runat="server" text=" - "></asp:button>
        <br />
        <asp:textbox id="txtinput2" runat="server"></asp:textbox>
        <asp:button id="btnmultiply" onclick="calc" runat="server" text=" x "></asp:button>
        <asp:button id="btndivide" onclick="calc" runat="server" text=" ÷ "></asp:button>
        <br />
        <strong>answer = <asp:label id="lblanswer" runat="server"></asp:label></strong>
    </form>
</body>
</html>

本文关键:[我的ASP.net学习历程]sender对象
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top