简体   繁体   English

ASP.NET Dynamic用户控件保存数据问题

[英]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} 会话中驻留的一组业务实体(例如, 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). 一组用户控件( using Telerik.Web.UI ),每个用户控件描述一个业务实体(例如EmployeeControl.ascx :用于名称,姓氏和薪水的RadTextBoxes和用于位置的RadComboBox。控件中还有一个RadButton ,它将在控件客户端中输入的数据保存到某个实体,该实体在加载控件时已经知道)。

  3. A page with a RadTabStrip and RadMultiPage , which is used to render different controls in different tabs 带有RadTabStripRadMultiPage页面,用于在不同的选项卡中呈现不同的控件

  4. The target RadTab that hosts our Employee control. 托管我们的Employee控件的目标RadTab

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. 因此, 问题是:当我按下“ Save按钮时,便完成了一个回发,从而清除了我的控件,并且仅在触发Click事件之后。 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. 我试图通过将RadAjaxManager与OnClientClicking脚本一起使用来取消回发来避免这种情况,但是没有成功,因为回发仍然生成,尽管它的__EVENTTARGETRadAjaxManager本身。

Basically, this is what happens: 基本上就是这样:

  1. The user selects a tab with the Employee control with it. 用户选择带有Employee控件的选项卡。 The control is filled with initial data on Page_Load . 该控件填充了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) (在重新创建控件时发生回发,然后触发Click事件)

  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). PS我通过将回发分为奇数和偶数(我在Session添加了另一个名为PostCounter的变量,每次递增)来实现所需的结果(尽管不完全:回发完成后屏幕“闪烁”)页面已发布)。 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. 因此,当表达式PostCounter % 2等于0时,我通过执行__doPostback执行另一次回发,该事件的eventTarget参数是RadAjaxManagerProxy实例的ClientID ,而参数只是与该字符串中使用的任何字符串都不匹配的字符串我的常规Ajax请求。

Make sure your controls always have the same IDs when recreated. 重新创建控件时,请确保它们始终具有相同的ID。 Imitating postbacks from other controls should not be needed, the buttons are IPostBack controls so things should work nicely. 不需要从其他控件模仿回发,按钮是IPostBack控件,因此一切正常。

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 对于Sharepoint,您需要以编程方式添加AJAX设置,这种(一种AJAX,一种完整的回发)行为是典型的: 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 . 另外,请确保不嵌套AJAX设置(来自管理器和/或代理),RadAjaxPanels和asp:UpdatePanels: http//www.telerik.com/help/aspnet-ajax/ajax-controls-in-ajaxpanel-和-ajaxsettings.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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