I have an html div element containing several divs with values ββthat I want to add to the array server!
my html divs looks something like this:
<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 to the array server. My current code is as follows:
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);
so the div id is generated in string format, no problem ...
but clientGrid.findControl always = null ! even if I put sting directly in a constructor like clientGrid.findControl("cell_0_0"); , it still returns NULL! How is this possible?
As far as I understand, the findControl method finds server controls with a string identifier?
I cannot access child divs directly, like cell_0_0.clientID , because child divs are generated by the server at runtime.
when the page loads, this function starts ...
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 the 2nd array containing integer values. these divs are then placed in clientGrid by clientGrid.innerHtml = allMyDivs
Then users change the values ββof these sections to whatever they want, and then, when the user clicks the button, the values ββof these divs must somehow go back to the serveride code so that I can process them.
ClientGrid.control.count = 0 ... ??? so itβs obvious ... for asp, these div elements do not exist ... for asp.net ... there is NOTHING inside the clientGrid div ... but ... the check element on my Chrome browser says othervise! What's happening?