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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:44:24+00:00 2026-05-25T02:44:24+00:00

I have a custom user control (ascx) that contains a textbox and a Javascript-based

  • 0

I have a custom user control (ascx) that contains a textbox and a Javascript-based counter to let the user know many characters they have left to type. In this control is the following:

function GetTextBox() {
    return document.getElementById("<%=txNotes.ClientID %>");
}

This worked fine when we only had one instance of this user control on the page, but now we have to support multiple. As you know, having multiple instances of this control on a page will result in multiple GetTextBox() functions, only the last of which will be called no matter what. To support multiple instances, I use this:

if (!string.IsNullOrEmpty(TextBoxName) && !Page.ClientScript.IsClientScriptBlockRegistered(TextBoxName))
{
    string Script = string.Format("function Get{0}Notes() {{ return document.getElementById(\"{1}\"); }}", 
        TextBoxName, txNotes.ClientID);

    Page.ClientScript.RegisterClientScriptBlock(GetType(), TextBoxName, Script, true);
}

TextBoxName is a public usercontrol property, so if the developer passes Employee through, it will generate a Javascript function called GetEmployeeNotes(). This works greate because now we can have a unique GetNotes() function.

However, I don’t like how it’s hardcoded into the codebehind. I would like a markup-based solution for this, something that doesn’t require a rebuild of the project in case I want to change the Javascript. Does anyone know of a way to do this?

Edit: I’ve already thought of creating a separate .js file that I could read with a text reader, but that sounds a bit hacky and I’d like to avoid that if at all possible.

Edit 2: Guard’s answer below would work, but I don’t want to go that route for the reason I gave beneath his answer. If no one can offer another way to do what I want to do, I will most likely mark his as the answer since it technically does exactly what I am asking.

  • 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-25T02:44:25+00:00Added an answer on May 25, 2026 at 2:44 am

    I’m not a .NET specialist, but isn’t it working as a preprocessor?

    Isn’t it legal to write

    function Get<%=Name %>Notes() {...}
    

    ?

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

Sidebar

Related Questions

I have a custom user control that contains asp:ValidationSummary . It is placed on
If I have a custom user control (say, MyCustomControl.ascx) which contains a number of
I have a custom user control with a textbox on it and I'd like
I have a custom validation function in JavaScript in a user control on a
I have a simple user control that contains some buttons that fire events which
I have a custom user control called ErrorNotificationBox. To place that on my page
I have hard time to modify a page that had a Custom User Control
I have this ListView that displays a custom user control. The custom user control
I have an custom control that extend System.Web.UI.UserControl. Is it possible to inherit user
I have a custom user control that fires an exception when trying to add

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.