简体   繁体   中英

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM