0

I'm finding some difficulties using JQuery on ASP.NET pages. In particular I have two main problems. I need to change the value of a Label and of a DropDownList using JQuery, then I have to read this values from code behind, but when I do it I find the original values. Changes made on client side are ignored.

How can I read correct values on server-side?

davioooh
  • 23,742
  • 39
  • 159
  • 250
  • All server-side code (your code-behind) on the page is executed on the server before the response is sent to the browser. To do something server-side in response to client changes you need to make another request to the web-server, most commonly either with a traditional form element submit or with Ajax. – nnnnnn Aug 02 '12 at 07:51
  • @nnnnnn I don't actually need an asynchronous response to client side changes. What I need is that posting back the form all changes are recognized on server side... – davioooh Aug 02 '12 at 08:00

2 Answers2

0

I once had a similar problem, the problem was event validation, http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation.aspx, it could be the same problem.

Xharze
  • 2,703
  • 2
  • 17
  • 30
  • Can you post a code example, please? I think your suggestion could be useful, but I cannot exactly understand how to apply it. – davioooh Aug 02 '12 at 08:20
0

Instead of using label and dropdown list to set the values,use Hiddenfield to set the value and then at the code behind get that value using HiddenField.Value.In most of the cases it is seen that Label and DropdownLists values which are set in Javascript code cannot be retrieved in code behind,but HiddenField Values can be retrieved.So try using HiddenField...

In Javascript:-

<script>
$("#HiddenField1").Val("Your Value");
</script>

In CodeBehind:-

string value=HiddenField1.Value;
Amol Kolekar
  • 2,307
  • 5
  • 30
  • 45