开发者

Invalid postback or callback argument error when using webservice to populate Dropdownlist

开发者 https://www.devze.com 2023-01-13 17:29 出处:网络
I have a drop down list on my page. The onchange event of this dropdownlist calls a web service using javascript/jquery. The webservice returns data that populates ANOTHER drop down list. When I do th

I have a drop down list on my page. The onchange event of this dropdownlist calls a web service using javascript/jquery. The webservice returns data that populates ANOTHER drop down list. When I do this and try to submit my form I get an invalid postback or callback error.

I know why it is occurring but cannot figure out how to stop this error. I found a few solutions about putting <pages enableEventValidation="false"/> in the web config. that is unfortunately not an option. Company doesn't allow it.

What may make it even trickier to solve is that these drop downs are all located in a control. Not it's own specific aspx page. Does anyone have any idea how to开发者_运维技巧 solve this?

Another thing that could make it trickier is that I have no idea what the ID of the control is. We use a framework here at work that gives the control added to the page some weird whacky ID when it gets added. Is this error even possible to avoid given all these constraints?

Thanks!


I had this issue as well and tried all the different solutions mentioned across multiple sites but nothing worked.

In the end I tracked down the control, a dropdown list that was causing the issue. The problem was to do with the data being used to populate it. I was reading rows from a database and the issue was that one of the rows on the table had a carraige return. Once I deleted that it resolved my problem.

Hope this helps someone.


Have you considered making your second DropDownList that is filled dynamically a basic HTML select list instead of using a asp:DropDownList? You could then check the posted value server side manually although you would have to handle any PostBack refreshes.

To address your other point about the control, that is not really a problem if you are using a asp:DropDownList. You can just embed the ClientID in the javascript with:

$('#<%= yourDDL.ClientID %>')

Or you could assign it a unique class and use the class selector in JQuery:

$('.yourUniqueClassForTheDDL')

Hope that helps. If not, just leave a comment :)

0

精彩评论

暂无评论...
验证码 换一张
取 消