AGuyCalledGerald
AGuyCalledGerald

Reputation: 8150

How to retrieve the value of a label/textbox etc., that has been calculated by jQuery

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:

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

Upvotes: 1

Views: 792

Answers (2)

StevenzNPaul
StevenzNPaul

Reputation: 188

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.

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630419

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");

Upvotes: 2

Related Questions