views:

21

answers:

2

I am using Javascript to alter the innerHTML attribute of a <td> and I need to get that info back in the form submittal. The <td> corrosponds to an <asp:TableCell> on the server-side, where the Text attribute is set to an initial value.

The user cannot enter the value in this particular field. Instead, its value is set by me (via client-side script) based on actions that the user performs. But this field is useless to me if I can't see its value on the server-side as well.

I'd like to avoid using a read-only textbox, because those are difficult to resize dynamically. Can an <asp:Label> be used as form data? Is there any way to achive this without letting the user manually enter the data? Or is there a simpler way to store a string as a variable somewhere and send it back as form-data?

+1  A: 

Add <input type="hidden" runat="server" id="myTDvalue"> to your form. Set that value via clientside script. Read it on the postback.

Jeff Meatball Yang
Thanks for the help!
Giffyguy
+1  A: 

You can only read data entered by user in any of html input elemnets, whatever you user sets them manually or you do it via javascript. You can use <asp:HiddenField runat="server" ID="somId" /> and set its value according to user actions on page.

miensol
He should be aware of the fact that the client id of the hidden field used for access in his client script will not be the same one set in the aspx markup
Pierreten
Oh great. What is the ID I should be using in the client-side script?
Giffyguy
it might or might not be depending if it is nested inside parent controls such as master pages or user controls
CRice
Basically Asp.net generates ids so it won't be equal to "somId" so the simplest way to set its value would be to wrap it with <div id="thisIdWillBeTheSame" > 'input goes here' </div>and then access it for example with jQuery $('#thisIdWillBeTheSame>input')or just use asp.net to generate id in javascript too :var idOfElemenetInJavascript = "<%=somId.ClientID %>";
miensol