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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:36:56+00:00 2026-05-22T01:36:56+00:00

I have a situation where I have a number of objects that are dynamically

  • 0

I have a situation where I have a number of objects that are dynamically created in code behind. Each object has a number of hidden fields, and an image button.

When the image button is rolled over I have a js file that should get the relevant fields for that object and do some stuff.

The trouble I have is that when I roll over the button I get a null refernce as the getEmelementById doesn’t nkow which object I’m refereing to.

Here is the ascx page:

    <div style="position:relative;float:right;" visible="true">
    <asp:ImageButton ID="iconNarrative" visible="true" ImageUrl="/_layouts/images/osys/NarrativeIcon.gif" runat="server" Style="position:absolute; top:-28px; left:-25px; display:block;" onmouseout="hideNarrative()" onmouseover="showNarrative(this, document.getElementById(id))" />
    <asp:HiddenField ID="hfNarrative" runat="server" Visible="true" />        
</div>    

Here is how it looks when rendered. there are 2 in this instance:

and

        <div style="position:relative;float:right;" visible="true">
    <input type="image" name="ctl00$m$g_90cae966_b430_4d11_8992_816553676250$ctl00$iconNarrative" id="ctl00_m_g_90cae966_b430_4d11_8992_816553676250_ctl00_iconNarrative" onmouseout="hideNarrative()" onmouseover="showNarrative(this, document.getElementById(id))" src="/_layouts/images/osys/NarrativeIcon.gif" style="border-width:0px;position:absolute; top:-28px; left:-25px; display:block;" />
    <input type="hidden" name="ctl00$m$g_90cae966_b430_4d11_8992_816553676250$ctl00$hfNarrative" id="ctl00_m_g_90cae966_b430_4d11_8992_816553676250_ctl00_hfNarrative" />        
    <input type="hidden" name="ctl00$m$g_90cae966_b430_4d11_8992_816553676250$ctl00$hfNarrativeDate" id="ctl00_m_g_90cae966_b430_4d11_8992_816553676250_ctl00_hfNarrativeDate" />
    <input type="hidden" name="ctl00$m$g_90cae966_b430_4d11_8992_816553676250$ctl00$hfNarrativeBy" id="ctl00_m_g_90cae966_b430_4d11_8992_816553676250_ctl00_hfNarrativeBy" />
</div>  

here is my javascript

var narrativeContainer = document.getElementById('narrative_container');
var narrative = document.getElementById('<%=hfNarrative.ClientID%>');
var narrativeBy = document.getElementById('<%=hfNarrativeBy.ClientID%>');
var narrativeDate = document.getElementById('<%=hfNarrativeDate.ClientID%>');  

narrative = document.getElementById('<%=hfNarrative.ClientID%>');

So how do I now which set of hidden fields where called?
The only thing I could think to do was get the Id and apend this to the various fields, then use the getElementById?

  • 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-22T01:36:57+00:00Added an answer on May 22, 2026 at 1:36 am

    Here’s my generic advice. I’ll assume that you’re using jQuery as well.

    First, it’s always helpful if you set your ClientIDs’ mode to static when you’re going to be accessing your server-side controls from JavaScript.

    Second, why is your data being passed into hidden fields? Is it modified and passed back? If not, the HTML5 standard for storing data is with attributes of the form data-attributeName="value".

    Here’s your HTML in your .ASCX page:

    <div id="hfNarrative" class="narratives" runat="server">
       <!-- Stuff specific to this object, image, buttons, whatever -->
    </div>
    

    On the .NET side, you can call:

    hfNarrative.Attributes.Add("data-narrativeDate", SOME_DATE);
    hfNarrative.Attributes.Add("data-narrativeBy", SOME_GUY);
    

    Then, with jQuery you can access these simply:

    $('div.narratives').each(function() {
        var $this = $(this);
        var narrBy = $this.attr('data-narrativeBy');
        var narrDat = $this.attr('data-narrativeDate');
        //Do stuff here with the data.
    });
    

    I hope this will help you down a more clean road.

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

Sidebar

Related Questions

I have a situation where I'm starting a number of objects that, when they
I have a situation where I'm creating a number of IDisposable objects that encapsulate
I have a specific situation where I've got an object that I want to
I have the following situation: a class Event that has a collection of Participant
I have a problem returning an object that was created in other thread. The
We have a situation where we want to limit the number of paralell requests
I have the following situation: A stackpanel contains a number of elements, including some
I have situation, where running a query that filters by an indexed column in
We have situation where say we have four engineers that are working on software
I have an application in which a number of objects are all extending an

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.