views:

72

answers:

2

I have a GridView with a Label. The value of the Label can be calculated with a jQuery-Method. When doing this, the (.Net-)server does not realise the change of the label, but works with the old value from the database.

I tried several approaches to fix it:

  • a TextBox behaving like a label doesn´t change anything
  • HiddenField: does´nt work because it has´nt a CssClass-property. I cannot raise the ID of the HiddenField because I want to put it in the GridView, and don´t know how to get the HiddenField in the jQuery-Method

The only way it works is with an empty TextBox, but it needs to be visible to get the text, in my experience. I do not want this.

Please give me advice and clear up, if I misunderstand something

+1  A: 

I'd still use a hidden field for this, who cares that the ASP.Net team didn't give it a CssClass property :)

<asp:HiddenField Id="myField" runat="server" class="myClass" />

It works, just isn't a property on the server control, it behaves like any attribute.

Alternatively, use the ends with selector to find it:

$("input[id$=myField]").val("something");
Nick Craver
We use this method as well, but we always prefix our controls with an '_' to avoid matching StateID when we just want the field ID.
Mark
A: 

I had come across this issue as well but my understanding of jquery manuplating the client side of the page like a label does not really update anything on the serverside because the labels are not really form field so won't get posted. So best option is to have a hidden column which will have a textfield in both templates item as well as edit then this information will be posted to the server on a postback, as in your case it is a grid. Hope this helps you.

StevenzNPaul
Thank you both, you really helped me, now my last try solved it,I used the <input type=hidden>-field and could get it by it´sclass-property. Don´t know how how to reward the answers here ;)
Jan-Frederik Carl