Jquery append + code-behind

I am dynamically adding rows to divStaff using jquery:

$("span[id$='lblAddStaff']").click(function() {
        //$(".staff_tpl").find("input[id$='txtRate']").val("0,00");
        var staff_row = $(".staff_tpl");
        staff_row.find(".staff_row").attr("id", "Emp" + counter);
        $("div[id$='divStaff']").append(staff_row.html());
        counter += 1;            
    });

      

the line I add is inside a hidden div with class = ". staff_tpl" I add the content of this div to divStaff

When I post the page (postback) the resulting divStaff is always empty if I try to display it like this:

lblTest.Text = divStaff.innerHtml.ToString

      

Basically, I am manipulating a client-side div and I want to get the server-side to it via the code of my aspx page. I think there is a basic principle missing here.

+2


source to share


1 answer


It's impossible. If you want to access the data that you pn created on the page, you have to put it in input fields (possibly hidden) and access it after posting it with Request.Form["MyHiddenFieldName"]

.
<div>

are not sent to the server. The elements are runat="server"

enechoded in ViewState (big line, really - you can see this in your page source), which gives an abstraction of continuity (or illusion). However, this sting is unaware of the changes you made to the DOM.
As you work with items runat="server"

, you will see the last changes you made on the server side, but the client side changes are gone.
Values โ€‹โ€‹only<input>

(and text area, parameter, etc.) are sent to the server when they are sent, so their change on the client will be visible on the server after this page is published.



+1


source







All Articles