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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:01:59+00:00 2026-05-12T17:01:59+00:00

I want the client id of an asp.net textbox control(txtTest) in javascript.But the problem

  • 0

I want the client id of an asp.net textbox control(txtTest) in javascript.But the problem here is the control id comes from a variable as shown below

var testName = 'txtTest';
var testCntrl = document.getElementById('<%=' + testName + '.ClientID %>');

But its throwing

CS1012: Too many characters in
character literal

Can any one please help….

  • 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-12T17:01:59+00:00Added an answer on May 12, 2026 at 5:01 pm

    <%= aspControlID.ClientID %> is a server side control, but you are trying to pass a clientside variable name to it. By the time testName is set equal to ‘txtTest’ its too late, you’re already on the client.

    There are a number of alternatives to get the server side ClientIDs as Rick Stahl discusses.

    1) You can pre-load all the control IDs that you know you’re going to need like this, they query them (he uses jquery) when you need their elements.

    var ids = { 
        txtSymbol: "#<%= txtSymbol.ClientID %>",
        PageContent: "#<%= PageContainer.ClientID %>"
    }
    

    This can also be written:

    var txtSymbol = document.getElementById('<%= txtSymbol.ClientID %>');
    var txtBlah = document.getElementById('<%= txtBlah.ClientID %>');
    

    2) Or, he wrote a function that will get a control for you from the clientside

    function $$(id, context) {
        var el = $("#" + id, context);
        if (el.length < 1)
            el = $("[id$=_" + id + "]", context);
        return el;
    }
    

    Be aware that there are some serious caveats. This relies on JQuery, so be sure to include that library and use it like this $$(‘myASPControlID’).val(‘new val’); The catch is that if you have any controls that create other controls, like listviews, repeaters, gridviews etc. Then finding a single instance of a child control will take some strategy. In that situation, this tool will only get the first instance of a repeated control.

    Still, the function provides a way to solve this problem by allowing you to specify a containing element in the second field.

    EDIT

    Hey L G, if you really need to pass your variable from the client side, then just add the second function and a link to the JQuery library. Then you can get your control with this simple code:

    var testName = 'txtTest';
    var testCntrl = $$(testName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a scheduled task to a client's ASP.NET app. These posts
I want to write a simple chat-client in Ruby for the terminal. The Problem
I want to consume a web service over https from a java client. What
i have a windows client and i want to upgrade subversion from 1.5.3 to
I want to call some RESTful web services from a J2ME client running on
I want to create a client side mail creator web page. I know the
I want to open a TCP client socket in Python. Do I have to
I want to build an Axis2 client (I'm only accessing a remote web service,
I want to connect to DB using the iSeries Client Access driver. I use
I want to create light object data-package to pass between client and server applications.

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.