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 8711637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:55:41+00:00 2026-06-13T04:55:41+00:00

I have a web app in ASP.NET with a C# code behind. The main

  • 0

I have a web app in ASP.NET with a C# code behind. The main login page is going to have a sort of touchpad type UI where there are buttons for 0-9 to enter a pin #.

So, I’m new to ASP.NET and to JavaScript both. When these numeric buttons are clicked on the UI, nothing needs to be done on the server side – there shouldn’t be any postback at all. All that needs be done is append a number to a label’s text. I’m trying to figure out how to do that in JavaScript, without the button causing any kind of postback.

To make the example much simpler, let’s just say I have a UI with a single label and single button on the screen, and everytime you click this single button, it should append a 1 to the label’s text. Here’s my .aspx, but when I try to run this, I get a “Object Expected” exception at runtime…

EDIT: I’ve modified my example to include the suggestions made in answers below, and still am having issues. To reproduce, this .aspx code can be copied into the default.aspx of a new VS Web Application project, and run it and click the 1 button; it should append a 1 to the label’s value, but it throws an “Object Expected” exception.

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestJavascript._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>
      <asp:Table ID="baseTable" runat="server" HorizontalAlign="Center">
        <asp:TableRow ID="labelRow" runat="server" HorizontalAlign="Center" Width="100" Height="30">
          <asp:TableCell ID="labelCell" runat="server" HorizontalAlign="Center" Width="100%" Height="100%" BorderStyle="Solid" BorderWidth="1px">
            <asp:Label ID="inputLbl" runat="server"/>
          </asp:TableCell>
        </asp:TableRow>
        <asp:TableRow ID="buttonRow" runat="server" HorizontalAlign="Center">
          <asp:TableCell ID="buttonCell" runat="server" HorizontalAlign="Center">
            <asp:Button ID="btn1" runat="server" Text="1" Height="70px" Width="70px" OnClientClick="btn1Click()"/>
          </asp:TableCell>
        </asp:TableRow>
      </asp:Table>
    </div>
  </form>
  <script type="txt/javascript">
    void btn1Click()
    {
        document.getElementById('<%= inputLbl.ClientID %>').value += "1";
        return false;
    }
  </script>
</body>
</html>

Any help is much appreciated!

  • 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-13T04:55:42+00:00Added an answer on June 13, 2026 at 4:55 am

    First of all, a variable name should not start with a number, so replace 1Btn with a significative name (btnAppendOne).

    1. Bind the onclick client event to your Button, in your PageLoad method:

      btnAppendOne.Attributes.Add("onclick", "return btnAppendOneClick();");
      
    2. Use the correct javascript (return false should cancel the postback):

      <script type="text/javascript">
           function btnAppendOneClick()
           {
               var updatedLabel = document.getElementById('<%=inputLbl.ClientID %>');
               updatedLabel.innerHTML = updatedLabel.innerHTML + "1";
               return false;
           }
      </script>
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an web app in asp.net, In the code behind I have
I have an old web app developed in ASP.Net with the old type code
I have a asp.net/c# web app. When do user leave a certain page, I
I am writing a web app in asp.net. I have an aspx page that
I have a asp.net web app. In my master page I have a calendar
The thing I have a web app (asp.net) which needs to have a feed.
I have a simple web app built in asp.net webforms c# where and how
I have a Silverlight web app which uses ASP.net Website administration tool for user
I have an asp.net web app. I want to separate out a particular section
Have an ASP.net web app which works fine for a few days, but then

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.