htmljquerygridviewpagination

A potentially dangerous Request.Form error when paging through gridView in update panel


Please excuse me if this is a duplicate question. I have searched and found many posts regarding this error, yet none of them seem to help me (perhaps due to my ignorance).

I am getting the value of a cell of a gridView and placing it in a hidden field. The gridview is in an updatePanel. Here is the code (jquery):

$('#<%=hdfCurrBatchId.ClientID %>').val($('.selectedRow td:first').html());

This works fine when loading the page and doing any action on the page. It works ok when changing the value of a dropdownList which is an AsyncPostBackTrigger to the updatePanel and causes the grid to reload (and the hidden field value to changes). I also works ok if I change the selectedRow.

But if I try to page through the grid, I get this error: A Potentially dangerous Request.Form value was detected from the client (ctl00$MainContent$hdfCurrBatchId=">T...").

I added to my web.config and I still get the error (I am using 4.0). I dont want to add valdiateInput = false because it compromises security. Is there anything else I can do? Am I doing something wrong with the way I am getting the value of the cell?

Thanks for your help. Let me know if there is any other code you need to see.


Solution

  • this is because you have content in the textbox/problem area that is considered dangerous... this is built into .NET to prevent script executing malware, or injections. Since you control this and if you feel safe doing it, put this at the top of your ASPX page, in the page directive:

    ValidateRequest="false" %>

    and by the way, this has nothing to do with JQuery.