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?

2
  • 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 2, 2012 at 7: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 2, 2012 at 8:00

2 Answers 2

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;
0
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.

1
  • 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 2, 2012 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.