简体   繁体   中英

ASP.NET Dynamic user controls save data issue

Here is what I have

  1. A set of business entities that resides in the session (for example, Employee:{"Name":string,"Surname":string,"Salary":double, "Position":enum}

  2. A set of user controls ( using Telerik.Web.UI ), each of it describing a business entity (for example, EmployeeControl.ascx : RadTextBoxes for Name, Surname and Salary and a RadComboBox for Position. There is also a RadButton in the control, which saves the data that is entered in the controls client-side to a certain entity, which is already known by the time the control is loaded).

  3. A page with a RadTabStrip and RadMultiPage , which is used to render different controls in different tabs

  4. The target RadTab that hosts our Employee control.

So, the issue is: when I hit the Save button, a postback is done, thus clearing my controls and only after that the Click event is fired. I have tried to avoid it by using RadAjaxManager with a OnClientClicking script with canceling the postback, but with no success, because a postback is still generated, although its __EVENTTARGET is RadAjaxManager itself.

Basically, this is what happens:

  1. The user selects a tab with the Employee control with it. The control is filled with initial data on Page_Load . (A postback occurs with re-creating my controls)

  2. The user modifies the data. (Nothing happens, no control generates postback)

  3. The user clicks save. (A postback occurs with re-creating my controls, then a Click event is fired)

  4. No data is saved

  5. When the data is entered again and the save is called, everything is saved as it should.

How can I make this work correctly?

PS I was able to achieve the required result (although not completely: the screen "flickers" when a postback is done) by dividing the postbacks into odd ones and even ones (I added another variable in Session named PostCounter, which is incremented every time the page is posted). So, when an expression PostCounter % 2 is equal to 0, I perform another postback by executing __doPostback with its eventTarget parameter being the ClientID of an instance of a RadAjaxManagerProxy, and the argument being just some string that does not match any that is used in my regular Ajax requests.

Make sure your controls always have the same IDs when recreated. Imitating postbacks from other controls should not be needed, the buttons are IPostBack controls so things should work nicely.

This (one AJAX, one full postback) behavior is typical for Sharepoint where you need to add AJAX settings programmatically: http://www.telerik.com/forums/radajaxmanager-in-webpart-on-sharepoint-2010

Also, make sure you do not nest AJAX settings (from a manager and/or proxy), RadAjaxPanels and asp:UpdatePanels: http://www.telerik.com/help/aspnet-ajax/ajax-controls-in-ajaxpanel-and-ajaxsettings.html .

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