ASP.NET - AJAX - 部分后跟完整的回发问题

时间:2021-11-10 03:38:32

I've a page that has a series of web controls. One of these is a textbox with AutoPostBack turned off.

我有一个页面,有一系列的Web控件。其中一个是关闭AutoPostBack的文本框。

The way the page operates is that a button is clicked to save the form data. This button sits outside of the updatepanel.

页面的操作方式是单击一个按钮以保存表单数据。此按钮位于更新面板之外。

So when I hit the save button the partial postback happens for the dropdownlist and after this postback has completed a full postback fires for the save button. However when the full postback fires the form data is returned to the state before the save button was clicked - i.e. my changes are removed.

因此,当我点击“保存”按钮时,下拉列表会发生部分回发,并且在此回发完成后,将为保存按钮完成一次完整的回发。但是,当完整的回发触发时,表单数据将返回到单击保存按钮之前的状态 - 即我的更改将被删除。

I believe this could be to do with the viewstate being returned from the partial update and that viewstate not updating in the page before the full postback fires - or it getting corrupted.

我相信这可能与部分更新返回的视图状态有关,并且视图状态在完全回发触发之前未在页面中更新 - 或者它已损坏。

Does anyone have any ideas?

有没有人有任何想法?

Thanks.

4 个解决方案

#1


Don't mean to sound negative but these scenarios are what made me give up "by the book" ASP.net AJAX. Learning jQuery /w simplistic ASP.net forms /w NO postbacks has lead me to build more useful and cooler UI experiences than what I had to battle to get working with update panels etc.

并不意味着听起来很消极,但这些场景让我放弃了“通过书”ASP.net AJAX。学习jQuery / w简单的ASP.net表单/ w没有回发让我构建更多有用和更酷的UI体验,而不是我为了使用更新面板等而战斗。

#2


If you set UpdateMode="Conditional" and ChildrenAsTriggers="true" on your UpdatePanel, that will ensure the partial postback only executes when the DropDownList's postback event fires, not when the Button is clicked.

如果在UpdatePanel上设置UpdateMode =“Conditional”和ChildrenAsTriggers =“true”,这将确保仅在DropDownList的回发事件触发时执行部分回发,而不是在单击Button时执行。

#3


Thanks for the quick response! However I need the save buttons click event to fire too. The order in which the events fire is perfect:

感谢您及时的回复!但是,我也需要点击保存按钮事件。事件发生的顺序是完美的:

  1. dropdownlist changed event (partial)
  2. 下拉列表更改事件(部分)

  3. save button click event (full)
  4. 保存按钮单击事件(完整)

The problem is the loss of form data after the partial postback.

问题是部分回发后丢失表单数据。

Many thanks.

#4


I've already posted a solution to this on another post. This simple code will ensure that your viewstate works with both the postback and partial postback.

我已经在另一篇文章中发布了一个解决方案。这个简单的代码将确保您的viewstate适用于回发和部分回发。

Ideas for how to deal with viewstate when using ASP.NET AJAX and update panels

在使用ASP.NET AJAX和更新面板时如何处理viewstate的想法

#1


Don't mean to sound negative but these scenarios are what made me give up "by the book" ASP.net AJAX. Learning jQuery /w simplistic ASP.net forms /w NO postbacks has lead me to build more useful and cooler UI experiences than what I had to battle to get working with update panels etc.

并不意味着听起来很消极,但这些场景让我放弃了“通过书”ASP.net AJAX。学习jQuery / w简单的ASP.net表单/ w没有回发让我构建更多有用和更酷的UI体验,而不是我为了使用更新面板等而战斗。

#2


If you set UpdateMode="Conditional" and ChildrenAsTriggers="true" on your UpdatePanel, that will ensure the partial postback only executes when the DropDownList's postback event fires, not when the Button is clicked.

如果在UpdatePanel上设置UpdateMode =“Conditional”和ChildrenAsTriggers =“true”,这将确保仅在DropDownList的回发事件触发时执行部分回发,而不是在单击Button时执行。

#3


Thanks for the quick response! However I need the save buttons click event to fire too. The order in which the events fire is perfect:

感谢您及时的回复!但是,我也需要点击保存按钮事件。事件发生的顺序是完美的:

  1. dropdownlist changed event (partial)
  2. 下拉列表更改事件(部分)

  3. save button click event (full)
  4. 保存按钮单击事件(完整)

The problem is the loss of form data after the partial postback.

问题是部分回发后丢失表单数据。

Many thanks.

#4


I've already posted a solution to this on another post. This simple code will ensure that your viewstate works with both the postback and partial postback.

我已经在另一篇文章中发布了一个解决方案。这个简单的代码将确保您的viewstate适用于回发和部分回发。

Ideas for how to deal with viewstate when using ASP.NET AJAX and update panels

在使用ASP.NET AJAX和更新面板时如何处理viewstate的想法