Click here to Skip to main content
15,749,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I used AJAX for Beginners (Part 2) - Using XMLHttpRequest and jQuery AJAX to implement a cascading dropdown[^]
The code worked properly. But if add a button and click, postback will cause error.
It is due to change in drop down list value after that it is issued by .Net.
What to do with this error? I need to use this way of updating menu.
Sandeep Mewara 9-Mar-13 6:55am    
Either you forgot to share the error in question or you expect us to guess and help you out!
A.Ebrahimi 9-Mar-13 7:07am    
Sandeep Mewara thank you. in the link above there is a sample code, it is for cascading drop down list filled by AJAx, Javascript. The code get data from webservice properly but it can not do postback and cause error. Just download the code, put a button on it, run the code and click to see error.
Sandeep Mewara 9-Mar-13 7:15am    
A suggestion: Rarely one will download anything from anywhere. Further, build and run the app to see the issue.

It is for your own benefit, if you add the error message (with stack trace if any) out here along with your question.

Ok: I use Asp.Net C# 2008, where I have drop-down list on page Country , state, city, used Javascript and xmlHttp to fill menu using webservice, and it is working properly.
when user select menus and try to post back data, it says:
Invalid postback or callback argument. ...
I searched and found that this is due to change in of menu item-list without notice. render code and send to client, then on post back to avoid injection, check all code with original ones, if something changed raise this error :Invalid postback or callback argument,....
Some suggest to disable EnableEventValidation="true" to false. But not a good way.
So question : How to inform server that these changes are legal?
Some suggest to use :
ClientScript.RegisterForEventValidation("ddlLanguages ", "English");
but it seems not the right answer.
Is it possible to inform .net about changes?
Is it possible to disable part of event validation for some objects?
Do you have any suggestion?
Share this answer
I tried to look into the problem and it seems the reason for the problem is:

When the page loads it has some values associated with the controls and knows about them (viewstate perhaps). Now we change the values on client side and them make a postback. this will make the to validate the values with the old values it knows about and they will not match. This will make it think that the some script is being injected.

Now this behavior is by default. To circumvent this problem, we can either use the AJAX mechanism that will update the values that knows along with the values on client side. This can be done by using the ASP.NET ajax framework to implement the cascading dropdows i.e. using Updatepanel.

Or we can turn of the event validation for the page having the xmlhttprequest code i.e. enableEventValidation="false"

Now this will open up the page for potential hacks in form of XSS but one should not solely rely on this eventvalidation to avoid XSS anyways. We need to have strong server side validations to check all the user input. Event validation is not always necessary if you our code does not use the values sent from the user. As long as we have strong server side validations put in place the event validations can be turned off(although not recommended.
Share this answer
I first appreciate your prompt and kind attention to my question and tweets.
Now instead of using this way Ajax, as a friend of mine suggested, I used jQuerry Ajax that inside it, updating is done automatically. But since I like to know what and how is something done, I would insist that there must be a way to overcome this error not by turning of page validation. If jQuerry is doing it, we must be able to do it, too. MS has issued some code but those are server side too I have commented it, hope to receive reply. Yet I keep this open for others to give their reply.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900