Trying to display a phone number as it is entered with buttons using asp.net

Trying to display a phone number as it is entered with buttons using asp.net

I am working on a project in which I am trying to have an empty label populate with the numbers that are being clicked. However, I am having trouble with my code behind my web form and cannot get it to work. My code behind:

I am working on a project in which I am trying to have an empty label populate with the numbers that are being clicked. However, I am having trouble with my code behind my web form and cannot get it to work. My code behind:

public partial class WebForm : System.Web.UI.Page
    {
        ArrayList phoneNumber = new ArrayList() { };
        int counter = 0;
        protected void Page_Load(object sender, EventArgs e)
        {

    }

    protected void btnNum1_Click(object sender, EventArgs e)
    {
        counter++;
        phoneNumber[counter - 1] = 1;
        lblNumbers.Text = phoneNumber.ToString();
    }

    protected void btnNum2_Click(object sender, EventArgs e)
    {

        counter++;
        phoneNumber[counter - 1] = 1;
        lblNumbers.Text = phoneNumber.ToString();
    }

My web form:

    <form id="form1" runat="server">
        <div class="container">
            <asp:Image class="img-fluid d-block mx-auto" ID="imgLogo" runat="server" ImageUrl="~/Images/logo.png"/>
            <div style="text-align:center; font-size:x-large; font-weight:800">
                <asp:Label ID="lblNumbers" runat="server" Text=""></asp:Label>
            </div>
      <table class="table table-bordered" style="margin:auto; width:250px; height:342px; background-image:url(Images/Telephone-keypad.png); background-repeat:no-repeat; background-position:center;" >
      <tbody>
      <tr>
          <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>
        <td><asp:Button ID="btnNum1" runat="server" OnClick="btnNum1_Click"/></td>
        <td><asp:Button ID="btnNum2" runat="server" OnClick="btnNum2_Click"/></td>
        <td><asp:Button ID="btnNum3" runat="server" OnClick="btnNum3_Click"/></td>
      </tr>
      <tr>
        <td><asp:Button ID="btnNum4" runat="server" OnClick="btnNum4_Click"/></td>
        <td><asp:Button ID="btnNum5" runat="server" OnClick="btnNum5_Click"/></td>
        <td><asp:Button ID="btnNum6" runat="server" OnClick="btnNum6_Click"/></td>
      </tr>
      <tr>
        <td><asp:Button ID="btnNum7" runat="server" OnClick="btnNum7_Click"/></td>
        <td><asp:Button ID="btnNum8" runat="server" OnClick="btnNum8_Click"/></td>
        <td><asp:Button ID="btnNum9" runat="server" OnClick="btnNum9_Click"/></td>
      </tr>
      <tr>
        <td><asp:Button ID="btnStar" runat="server" OnClick="btnStar_Click"/></td>
        <td><asp:Button ID="btnNum0" runat="server" OnClick="btnNum0_Click"/></td>
        <td><asp:Button ID="btnPound" runat="server" OnClick="btnPound_Click"/></td>
      </tr>
    </tbody>
  </table>
        </div>
    </form>

When each button is clicked, I want the numbers that are clicked to display in the label as they are clicked. Currently, when I click on a button, it gives me an error page that states:

Index was out of range. Must be non-negative and less than the size of the collection.

It also includes this:

Source Error:

Line 21: { Line 22: counter++; Line 23: phoneNumber[counter - 1] = 1; Line 24: lblNumbers.Text = phoneNumber.ToString(); Line 25: }

Can someone please help?

c-sharp asp.net

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire ASP.Net Developers

Looking to outsource your asp dot net development requirement? ASP.Net is a special feature of the DOT Net framework created by Microsoft. At [HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io"), we have a team of experienced...

Various ways of redirecting a request in Asp.Net Core

ASP.NET Core web applications often need to redirect a request to another resource based on some condition. There are multiple ways in which you can accomplish this task in ASP.NET Core MVC and Razor&#160;&#8230;

Routing in MVC - ASP.NET Core Demystified

ASP.NET Core MVC has introduced quite a few concepts that new (or new-to-ASP.NET) web developers might have some difficulty getting caught up with. My ASP.NET Core Demystified series is designed to help these developers get started building their own custom, full-fledged, working AASP.NET Core applications. In

What is the ASP.Net Machine Account on my Computer?

Some users have reported the existence of the ASP.Net machine account. In this article, I will discuss what is asp.net machine account in windows 10/7 and how to disable it, asp.net machine account password, and can I delete asp.net machine account? .NET Framework is an application on Windows that requires the installation to run several apps or games. However, when the .NET Framework is downloaded and installed, the application automatically creates an ASP NET machine account.

ASP.NET Community Standup - ASP.NET Core Linker with David Fowler

David Fowler will be showing ASP.NET Core linker improvements on the way for .NET 5, and probably some other crazy experiments. Come join the fun! Community ...