asp.net - How to get div content which changed by javascript? -
I have a device on the page, which will change the content from Javascript, I want to get its value from the C # code. But, it always gives blank or initial value, not converting value.
If I'm hidden from Div, then it works well. I do not know why?
Here is the code:
& lt; Head runat = "server" & gt; & Lt; Title & gt; Untitled Page & lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Foo = function () {var d = document.getElementById ('divTest'); D.innerHTML = 'My Values'; Var e = document.getElementById ('hidden'); E.value = 'my value'; } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Div & gt; & Lt; Div id = "divTest" runat = "server" / & gt; & Lt; Input type = "hidden" runat = "server" id = "hidden" /> & lt; Input type = "button" value = "test" onclick = "javascript: foo ();" / & Gt; & Lt; ASP: Button ID = "BTN Test" runat = "server" text = "ASP.Net button" onclic = "on button test" /> & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt;
Here is the C # code:
Secure void OnbtnTest (Object Sender, EventArgs e) {Response.Write (string.Format ("alert (' {0} '); ", hiddenTest.Value)); }
Format the input elements inside a form element positioned on the server, all others The content is stable and not posted to the server. This is the basic rule of HTTP, you can see the details.
When you prepare your Div content, you have two options, write the same content inside a hidden area. And the value of hidden field on server side is found.
Or make an AJMX call while preparing your content on the server side.
Comments
Post a Comment