简体   繁体   English

计算器Web应用程序不起作用

[英]Calculator Web Application Doesn't Work

Hi I need to make a calculator for school but when I click on button 1 number 1 is not coming into the textbox. 嗨,我需要为学校制作一个计算器,但是当我单击按钮1时,数字1并未出现在文本框中。

This is the aspx code I have: 这是我的aspx代码:

protected void btn1_Click(object sender, EventArgs e)
{
    // controleer of er minder dan 7 tekens staan
    if (txtScherm.Text.Length < 7)
    {
        txtScherm.Text += "1";
    }
}
<asp:Table ID="Table2" runat="server">
    <asp:TableRow>
        <asp:TableCell><asp:TextBox runat="server" ID="txtScherm"></asp:TextBox></asp:TableCell>
    </asp:TableRow>
</asp:Table>

<asp:Table ID="Table1" runat="server">
    <asp:TableRow>
        <asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" /></asp:TableCell>
        <asp:TableCell><asp:Button ID="btn2" runat="server" Text="8" Height="50" Width="50" /></asp:TableCell>
        <asp:TableCell><asp:Button ID="btn3" runat="server" Text="9" Height="50" Width="50" /></asp:TableCell>
        <asp:TableCell><asp:Button ID="btn4" runat="server" Text="C" Height="50" Width="50" /></asp:TableCell>
        <asp:TableCell><asp:Button ID="btn5" runat="server" Text="Back" Height="50" Width="50" /></asp:TableCell>
    </asp:TableRow>

You have to modify your code like this : 您必须像这样修改代码:

<asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" OnClick="btn1_Click"/>

and do the same for all your buttons with the right event. 并使用正确的事件对所有按钮执行相同的操作。

You didn't set the Click Event for btn1: 您没有为btn1设置Click事件:

change: 更改:

<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" /></asp:TableCell>

to: 至:

<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" Click="btn1_Click"/></asp:TableCell>

如下所示添加OnClick =“ btn1_Click”

<asp:TableCell><asp:Button ID="btn1" runat="server" Text="7" Height="50" Width="50" OnClick="btn1_Click"/></asp:TableCell>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布后Web应用程序不起作用 - Web Application doesn't work after publish 通过网址启动ClickOnce应用程序在Windows 8中不起作用 - Launch ClickOnce application via web url doesn't work in windows 8 我的计算器无法使用C#控制台应用程序 - My calculator won't work c# console application 与Oracle的连接通过控制台应用程序运行,而无法通过Web应用程序运行-ORA-12154 - Connection to Oracle works through a console application and doesn't work through a web application - ORA-12154 .WaitForExit();从C#和.NET自动启动java-web-start应用程序。 不能按需工作 - Automatically starting a java-web-start application from C# and .NET, .WaitForExit(); doesn't work as desired API Controller 添加到 ASP.NET MVC web 应用程序似乎不起作用 - API Controller added to ASP.NET MVC web application doesn't seem to work Visual Studio 2015 Update 2 Web应用程序(窗体)“编辑并继续”不起作用 - Visual Studio 2015 Update 2 Web Application (Forms) Edit & Continue doesn't work 启用 https 时,应用程序设置中的连接字符串不起作用:Azure Web App - Connection string in application settings doesn't work when https is enabled: Azure Web App 与Oracle的连接通过控制台应用程序工作,不能通过Web服务工作 - Connection to Oracle works through a console application and doesn't work through a web service asp.net MVC Web应用程序日期选择器不起作用 - asp.net MVC web application date picker doesn't work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM