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

  • SEARCH
  • Home
  • 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 6329069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:34:52+00:00 2026-05-24T17:34:52+00:00

Ok, so I have a multiple ASP textboxes and ASP buttons on a page

  • 0

Ok, so I have a multiple ASP textboxes and ASP buttons on a page within a multiview.
The submit button associated with each textbox should be enabled only when there is text entered in the textbox. So, I wrote a Javascript function to handle this and I’m getting an error saying “document.getElementById(…)’ is null or not an object”

    function checkEmptyTxtBox(val, savebtn) {
        if (val.value.replace(/^\s+|\s+$/g, "") == "")
            document.getElementById(savebtn).disabled = true;
        else
            document.getElementById(savebtn).disabled = false;
    }

                   <asp:TextBox 
                    ID="txt_Comments_2" 
                    runat="server" 
                    Wrap="true" 
                    TextMode="MultiLine" 
                    onkeyup="checkEmptyTxtBox(this,'<%= btnSave2.ClientID %>')">
                 </asp:TextBox>

                 <asp:Button 
                    ID="btnSave2"
                    runat="server"
                    text="Save" 
                    Enabled="False"/>

This is on VS2010.

  • 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-05-24T17:34:56+00:00Added an answer on May 24, 2026 at 5:34 pm

    You cannot set an attribute of a Server Side Control using <%= %>. If you look at the rendered source, it looks like this:

     onkeyup="checkEmptyTxtBox(this,&#39;&lt;%= btnSave2.ClientID %>&#39;)"
    

    It literally contains the <%= %>.

    You could set the attribute on page load like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        txt_Comments_2.Attributes["onkeyup"] = "checkEmptyTxtBox(this,'" + btnSave2.ClientID + "')";
    }
    

    EDIT:

    As many will be willing to point out; this isn’t really the “best” way to do event registration in HTML. Rather, the JavaScript should bind to the keyup event by adding an event listener. For example, with jQuery it becomes:

    $(document).ready(function() {
        $('#<%: txt_Comments_2.ClientID %>').keyup(function() {
            if ($(this).val().replace( /^\s+|\s+$/g , "") == "") {
                $('#<%: btnSave2.ClientID %>').attr('disabled', 'disabled');
            }
            else {
                $('#<%: btnSave2.ClientID %>').removeAttr('disabled');
            }
        });
    });
    

    And your ASP.NET markup looks like this:

    <asp:TextBox 
        ID="txt_Comments_2" 
        runat="server" 
        Wrap="true" 
        TextMode="MultiLine" />
    
    <asp:Button 
        ID="btnSave2"
        runat="server"
        text="Save" 
        Enabled="False"/>
    

    This has the advantage of not cluttering your HTML with event registration. There are even other, perhaps cleaner ways of doing this with something like KnockoutJS.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with multiple textboxes and each has a button associated with
I have multiple textboxes with the same class .input. Each textbox has different default
Is it possible to have multiple login pages for different folders within an asp.net
I have multiple literals on a page. For example, <asp:Literal id=Label1 runat=server /> I
I have an ASP.NET MVC page with multiple file uploads. After a failed post,
I have an ASP.NET 3.5 page which has multiple span elements with ID containing
There are multiple values I have been storing in ASP.NET configSections sections for each
I have multiple master pages in my asp.net mvc web application... Each of the
I have a standard asp.net webform with multiple textboxes (Autopostback=False) on it and a
I have an ASP.NET page that requires the ability to have users enter multiple

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.