开发者

Add asp.net dropdownlist item from JavaScript causes page postback error

The design is:

all elements are in an updatepanel.

click on a list of <tr> to fire a JavaScript function to add new <option> to the asp dropdownlist.

But, when I click on other buttons to callback to the server, I get an error message:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this featu开发者_StackOverflow中文版re verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

I understand the problem. I need to let server side know the change of the dropdownlist before any other postback.

Set validation as false won't work in this case, the dropdown will lose the new item anyway.

I did some researches, and the possible solutions:

1)Using ViewState? Request Form? could anyone give an example?

2)Add dropdownlist item in server side. But I want to make the whole tr row clickable to fire the event. Could I click on tr and fire eg. its first child linkbutton or a linkbutton in somewhere else.

3)I've tried Jquery.ajax and webmethod , it can fire server event but since all method are static (shared) , it doesn't allow me to edit the downdownlist instance.

Any kinds of solution will be helpful!!

Regards,


You should trigger a server side event handler to update the list from javascript as described in this article. http://codeclimber.net.nz/archive/2007/06/26/how-to-refresh-an-updatepanel-from-javascript.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜