Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:14:45+00:00 2026-06-12T12:14:45+00:00

this code is a excerpt from the book asp.net all in one reference for

  • 0

this code is a excerpt from the book asp.net all in one reference for dummies on pages 18 and 19. The problem with this is that it doesn’t compile. The compiler says txtFirst, txtSecond and lblAnswer are not found in the current context. I am new in this field, could someone please help me out ?

<%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0
Transitional//EN" “http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Simple Calculator</title>
</head>
<body>
    <form id="form2" runat="server">
        <div>
            <h1>The Simple Calculator</h1>
            First number:
            <asp:TextBox ID="txtFirst" runat="server" />
            <br />
            <br />
            Second number:
            <asp:TextBox ID="txtSecond" runat="server" />
            <br />
            <br />
            <asp:Button ID="btnAdd" runat="server"
                OnClick="btnAdd_Click" Text="Add" />
            <br />
            <br />
            The answer is:
            <asp:Label ID="lblAnswer" runat="server" />
        </div>
    </form>
</body>
</html>



using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace WebApplication2
{
    public partial class _Default : System.Web.UI.Page
    {

        protected void btnAdd_Click(object sender,EventArgs e)
        {
            decimal a = decimal.Parse(txtFirst.Text);
            decimal b = decimal.Parse(txtSecond.Text);
            decimal c = a + b;
            lblAnswer.Text = c.ToString();
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:14:47+00:00Added an answer on June 12, 2026 at 12:14 pm

    Try this version instead – I’ve tested it and it works:

    ASPX:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" 
        Inherits="Test.Default" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <h1>The Simple Calculator</h1>
                First number:
                <asp:TextBox ID="txtFirst" runat="server" />
                <br />
                <br />
                Second number:
                <asp:TextBox ID="txtSecond" runat="server" />
                <br />
                <br />
                <asp:Button ID="btnAdd" runat="server"
                    OnClick="btnAdd_Click" Text="Add" />
                <br />
                <br />
                The answer is:
                <asp:Label ID="lblAnswer" runat="server" />
        </div>
        </form>
    </body>
    </html>
    

    CODE-BEHIND:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    
    namespace Test
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void btnAdd_Click(object sender, EventArgs e)
            {
                decimal a = decimal.Parse(txtFirst.Text);
                decimal b = decimal.Parse(txtSecond.Text);
                decimal c = a + b;
                lblAnswer.Text = c.ToString();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a sample code from a jQuery book that rotates through images. I
This is an excerpt of some c++ code, that i'll have to explain in
I have the following HTML (excerpt from larger code-base) <div class=diary-event ui-corner-all title=[title]> <span
This is an excerpt from my code: <div id=column2> <div id=textbox> <h3>About</h3> <div id=text>
I understand all of the following code from an example on a book I'm
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't
I implemented this Jquery show/hide code and everything works fine except that the box
This is pretty much the same problem i have, except with very different code:
I've seen code examples (from the book Beginning iPhone 4 Development) where they both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.