Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Wednesday, March 28, 2012

Page with AJAX controls posts back twice to the server

I have a form containing three AJAX UpdatePanels, two of which contain a pair of listboxes and a pair of buttons, with the third one containing a pair of radio buttons in a radiobutton list and either three CascadingDropDown lists or two CascadingDropDown lists and a textbox depending on which radio button is selected. The only other control on my form is a button to submit the information on the form to the server.

One thing I've noticed is the information gets posted back to the server twice when the button is clicked. This causes a duplicate record to be written to two tables and a SQL exception being thrown when it tries to write a duplicate record to a third table since it violates that table's primary key constraint. At first, I thought the cause might've been due to the submit button being contained in the third UpdatePanel I mentioned, so I removed it from there and placed it by itself ... but the problem still occurs. One other thing I've noticed is that when data for one of the UpdatePanels is to be updated via a postback to the server, the other two UpdatePanels act as if they're also being posted back to the server; in other words, all three panels noticeably flicker simultaneously. I have a sneaking suspicion this may somehow tie into my entire page being posted back twice when the submit button is clicked, but I'm not at all sure.

What can I do to prevent my page from being posted back twice?

Hi,

any sync postback at the server side is almost identical to regual postback including:

- all control values are posted to the server
- Viewstate is transferred to the server and back

The most important difference is in the rendering phass: only update panels are rendered and their content transferred to the client

So, you must design your application in such a way, that removing all update panels will not break server logic. UpdatePanels reduce flickering, but they don't change how server code process data.

-yuriy


I think there a couple things that can cause this... I think ImageButtons can get rendered as "Submit" buttons, and have a __doPostBack call attached to their OnClick, which seems to make a double postback. Also, I think a button has a UseSubmitBehavior property... try setting that to false.

PageMethods call from user controls (ascx)

Hello,

i am looking for a way to call webmethods defined in an (ascx) user control (not a web form page aspx) using PageMethods.{MethodName}. For now, i only get a javascript error saying that PageMethods is not defined. Is there a different syntax to acces thos methods or is it just not possible ?

Thank you for your help

thomas

Any answer would be appreciated.

Thank you

thomas


hello.

currently, you can only call web service methods or page methods (and in this case, the methods must be static)

Monday, March 26, 2012

PageRequestManagerParserErrorException caused by Response diddling?

I am porting an old app that downloads a csv file by writing into Response.OutputStream when a button is pushed on the form. The button is contained in an asp:Panel that can be made visible or not, so the Panel needs to be contained in the UpdatePanel.

If the asp:Panel and button are in an update panel, I get PageRequestManagerParserErrorException. If the panel and button are NOT in an UpdatePanel, the download works okay, but of course, I lose the ability to show/hide the asp:Panel.

My question is--is there a way to have a button in an UpdatePanel, but tell it NOT to participate in partial page rendering?

Or is there a better way to do the download??

Thanks,

R.L.

Hi Rlparker,

If you want a button not to participate in partialrendering then you have to make sure that you the button as a postback trigger. This will make sure that the button will act normally as a normal button event. See:

http://ajax.asp.net/docs/mref/T_System_Web_UI_PostBackTrigger.aspx

Hope this helps.

Regards,


Sorry

"you have to make sure that you the button as a postback trigger"

you have to make sure that you define the button as a postback trigger

Regards,


Thanks!!

R.L.