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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:04:03+00:00 2026-05-22T17:04:03+00:00

I have a html div element containing multiple divs with values that I want

  • 0

I have a html div element containing multiple divs with values that I want to put in an array server side!

my html divs look something like:

<div id="clientGrid" runat="server">
    <div id="cell_0_0" runat="server" class="box" onclick="clicked(this)">2</div>
    <div id="cell_0_1" runat="server" class="box" onclick="clicked(this)">1</div>
    <div id="cell_0_2" runat="server" class="box" onclick="clicked(this)">3</div>
    <div id="cell_0_3" runat="server" class="box" onclick="clicked(this)">4</div>

    <div id="cell_1_0" runat="server" class="box" onclick="clicked(this)">3</div>
    <div id="cell_1_1" runat="server" class="box" onclick="clicked(this)">2</div>
    <div id="cell_1_2" runat="server" class="box" onclick="clicked(this)">4</div>
    <div id="cell_1_3" runat="server" class="box" onclick="clicked(this)">1</div>

    <div id="cell_2_0" runat="server" class="box" onclick="clicked(this)">4</div>
    <div id="cell_2_1" runat="server" class="box" onclick="clicked(this)">3</div>
    <div id="cell_2_2" runat="server" class="box" onclick="clicked(this)">2</div>
    <div id="cell_2_3" runat="server" class="box" onclick="clicked(this)">1</div>
</div>

i want the values of these divs to go into an array server side. My current code looks like this:

for (int i = 0; i < _grid.getGridSize(); i++)
{
    for (int j = 0; j < _grid.getGridSize(); j++)
    {
        string divId = string.Format("cell_{0}_{1}", i.ToString(), j.ToString());
        Control div = clientGrid.findControl(divId);
        //more code underneath
    }
}

so the div id’s are generated by the string format, no problem…

but the clientGrid.findControl always = null! even if i put the sting directly into the constructor like clientGrid.findControl("cell_0_0"); it still returns NULL! How is this possible?

It is my understanding the the findControl method finds server control elements with the string id?

I can’t access the child divs directly like cell_0_0.clientID because the child divs are generated by the server at runtime.

on page load, this function is run…

    for (int i = 0; i < _grid.getGridSize(); i++)
    {
        for (int j = 0; j < _grid.getGridSize(); j++)
        {
            returnElement += " <div ";
            returnElement += "id=\"cell_" + i + "_" + j + "\" ";
            returnElement += "runat=\"server\" ";
            returnElement += "tabindex=\"-1\" ";
            returnElement += "class=\"box\" ";
            returnElement += "onclick=\"clicked(this);\" ";
            returnElement += "onkeypress=\"changeValue(event, this);\" ";
            returnElement += "style=\"top:" + top + "%; left:" + left + "%;\">";

            returnElement += test[i, j];

            returnElement += "</div>\n ";

            left = left + 20;
        }
        left = 0;
        top = top + 20;
    }
    return returnElement;

test[,] is a 2d array containing integer values. these divs are then put into clientGrid by clientGrid.innerHtml = allMyDivs

The users then edits the values of these divs to whatever they want, and then when the user clicks a button, the values of these divs need to somehow end up back in the serverside code so i can process them.

The clientGrid.control.count = 0 … ??? so obviously… to the asp, these div elements do not exist… to asp.net… there is NOTHING inside the clientGrid div… but… the inspect element on my chrome browser says othervise! Whats Going On??

  • 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-22T17:04:03+00:00Added an answer on May 22, 2026 at 5:04 pm

    Try using the asp:Panel control, which is an HTML div element, instead.

    This would allow you to streamline your code:

    Client Side:

    <asp:Panel ID="clientGrid" runat="server" />
    

    Server Side:

    for each row
      for each col
        Panel p = new Panel();
        p.ID = "cell_" + row.tostring() + "_" col.tostring();
        p.Text = "&nbsp;";
        p.OnClientClick = "javascript:blah";
        clientGrid.Controls.Add(p);
    

    You could even just use an asp:Placeholder and programmatically add all controls to that.

    Then on postback you need to re-render the page in the init event. All controls that were dynamically created need to be re-created and re-added to the page on every single postback to restore the page state.

    You can then do:

    clientGrid.FindControl("Cell_0_0")
    

    after you’ve re-rendered all of the controls.

    There’s a ton of posts about dynamically rendered asp.net controls all over the internet.

    Another option is to the put a hidden control for each cell onto the form and, using javascript, place the value from each cell into the respective hidden control on submit and use Request.Form(“Cell_0_0”).

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

Sidebar

Related Questions

I have a div element containing a few other divs with an id of
I want to append an html element to a div and have jquery return
I have a div element in an HTML document. I would like to extract
I have the following html: <div id=container> <ul> <li>element 1</li> <li>element 2</li> </ul> </div>
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have some HTML and jQuery that slides a div up and down to
I have some HTML that I insert into a div using javascript. But it
Cosmetic question: I have a html element containing possible dimensions for some embedded images,
I have a Web Content Form containing a Div and various Server controls like
I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>

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.