UpdatePanel 内的 Jquery UI 对话框做奇怪的事情

发布于 2024-08-10 10:07:14 字数 742 浏览 0 评论 0原文

我有一个 DIV,其中有一个 asp:repeater,它根据数据将信息放入此 div 中。然后,我使用 Jquery 的 UI 对话框通过单击按钮向用户显示数据。这一切都很顺利。

因此,我希望能够将记录添加到填充中继器的数据中。我有屏幕的另一部分,人们可以在其中输入这些数据,并使用 ajax 调用将其保存到数据库中。这也很顺利。

然后,我想更新对话框上的数据,而不必完全回发到服务器。所以,这通常很容易。我将 div 放入 UpdatePanel 中,并从 Jquery 启动 __doPostBack。然后刷新数据,这在某种程度上也可以顺利进行。

一旦 __doPostBack 完成,div 就不再隐藏。它现在显示在我的页面上(请注意,更新的数据),但我用来显示对话框的 JavaScript 现在不再起作用。

一些调查表明:

  1. 在页面的初始加载时,告诉 jquery 从 div 创建对话框的 javascript 从表单上的任何位置获取 div,并将其附加到 body 元素。
  2. 当更新面板发回时,会重新创建 div,但是将其转换为对话框的 javascript 不会再次执行(我可以理解......我们还没有完全加载页面,因此 javascript 。
  3. 这意味着该 div 不再是一个“对话框”,而是我的页面上的一个简单的 div,这不是我想要的,

所以,我的问题是:

有没有一种方法可以在 updatepanels 回发之后注入 javascript 会再次正确执行并创建对话框吗?

I have a DIV in which I have a asp:repeater which, based on data, puts information in this div. I then use Jquery's UI dialog to display the data to the user via a button click. This all works swimmingly.

So, I want to be able to add records to the data which populates the repeater. I have another part of the screen where people can enter this data, and it is saved to the database using an ajax call. This, too, works swimmingly.

I then want to update the data on my dialog box, without having to do a full postback to the server. So, this is normally pretty easy. I put my div into an UpdatePanel, and from Jquery initiate a __doPostBack. which then refreshes the data, which too, works swimmingly up to a point.

Once the __doPostBack is complete, the div is no longer hidden. It is now displayed on my page (with the updated data mind you), but the javascript i use to show the dialog, now no longer works.

Some investigation shows that:

  1. On initial load of the page, the javascript which tells jquery to create a dialog from a div takes the div from wherever it is on the form, and appends it to the body element.
  2. When the update panel posts back, the div is recreated, but the javascript to turn it into a dialog either isn't executed again (which I can understand... we haven't done a full load of the page, so the javascript doesnt execute again.
  3. This means that the div is no longer a 'dialog' but a simple div on my page, which is not what I want.

So, my questions are is:

Is there a way of injecting javascript aftr the updatepanels postback which will execute and create the dialog properly again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

姜生凉生 2024-08-17 10:07:14

解决方案是根本不使用 Updatepanel,而只需使用通过 jquery ajax 调用接收到的数据更改 div 的innerHTML。

The solution would be not to use Updatepanel at all and just change the innerHTML of the div with data received through a jquery ajax call.

り繁华旳梦境 2024-08-17 10:07:14

我找到了另一个解决方案。我将对话框初始化 javascript 放在一个名为 SetupDialog 的单独函数中,而不是放在 $(function () { }); 块内。

然后我在 Page_Load 中使用 ScriptManager.RegisterStartupScript 来注册脚本,以便它在每次更新面板更新时运行:

ScriptManager.RegisterStartupScript(this, GetType(), "SetupDialog", "SetupDialog();", true);

在这种情况下,该对话框仅在 UpdatePanel 更新后才起作用。如果您之前需要对话框,那么您也可以在 $(function () { }); 块内调用SetupDialog。

I found another solution to this. I put the dialog initialization javascript in a separate function called SetupDialog instead of being inside the $(function () { }); block.

Then I used ScriptManager.RegisterStartupScript in Page_Load to register the script so that it runs every time the Update Panel updates:

ScriptManager.RegisterStartupScript(this, GetType(), "SetupDialog", "SetupDialog();", true);

In this case, the dialog will only work after the UpdatePanel has been updated. If you need the dialog before that, then you can call SetupDialog inside the $(function () { }); block as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文