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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:45:07+00:00 2026-06-11T15:45:07+00:00

I have asp .net user control that has <%= myDiv.ClientID %> in a piece

  • 0

I have asp .net user control that has <%= myDiv.ClientID %> in a piece of javascript hosted in the html template.

This control is placed on a page a number of times. The problem is that the above statement is always returning the client id of the div in the last control on the page.

I have checked the HTML and each div is given its own unique ID.

The full HTML of the control is…

<script type="text/javascript">
    function ToggleHelpText() {
        try {

            var e = document.getElementById("<%= divHelpText.ClientID %>");

            if (e.style.display == 'block')
                e.style.display = 'none';
            else
                e.style.display = 'block';
        }
        catch (err) {
            alert(err);
        }
    }
</script>
<asp:LinkButton ID="Help" OnClientClick="ToggleHelpText(); return false;" CausesValidation="false"
    OnClick="btnHelp_Click" runat="server">Help</asp:LinkButton>
<div id="divHelpText" runat="server" visible="true" style="display: none">
</div>

What could be causing this and what is the work around?

Thank you

  • 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-11T15:45:09+00:00Added an answer on June 11, 2026 at 3:45 pm

    Your problem is that you’re defining the function ToggleHelpText multiple times. Each definition has the ID of one control hardcoded into it, and you’re only left with the last definition and the last ID as they overwrite each other.

    As a simple step, change your code to

    <script type="text/javascript">
     function ToggleHelpText(id) {
         try {
              var e = document.getElementById(id);
              if (e.style.display == 'block')
                 e.style.display = 'none';
             else
                 e.style.display = 'block';
         }
         catch (err) {
             alert(err);
         }
     }
    </script>
    <asp:LinkButton
      ID="Help"
      OnClientClick='ToggleHelpText(\'<%= divHelpText.ClientID %>\'); return false;'
      CausesValidation="false"
      OnClick="btnHelp_Click" runat="server">Help</asp:LinkButton>
    <div id="divHelpText" runat="server" visible="true" style="display: none">
      </div> 
    

    This will continue to overwrite the function multiple times, but now the ID itself will not be overwritten as it’s not hardcoded into the function.

    In future you can figure out how not to define the function multiple times.

    NB I’m a little unsure of the quoting in the OnClientClick. If it doesn’t work, try this

    OnClientClick='ToggleHelpText(<%= "\"" + divHelpText.ClientID + "\""%>); return false;'
    

    or try setting it in code:

    Help.OnClientClick =
        "ToggleHelpText('" +
        divHelpText.ClientID +
        "'); return false;";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET user control that contains a textbox which has an AJAX
I have used Subsonic ORM in ASP.NET. It has Scaffold user control that generates
I have a asp.net usercontrol (.ascx). the user control has a HTML hidden field.
I have an ASP.NET user control (.ascx file). In this user control I want
I have an ASP.NET user control that is used in another use control. The
I have an ASP.NET Page that contains a User control called ReportCtrl (my own
I have an ASP.NET MVC web page that has a file upload control. Under
My asp.net application has a custom base user control that is inherited from other
I have a large HTML file (In ASP.NET) that has several smaller ... tags
I have say this hierarchy in ASP.NET: page user control 1 user control 2

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.