3

我有当前的问题,让我们解释一下之前的上下文:

我有一个包含表单的模态弹出扩展器。有一个功能“保存并添加新”,当用户单击此按钮时,表单中的数据在回发期间保存在数据库中并重新加载页面。

我希望此 Modal 弹出窗口再次出现在 page_load 上,允许用户输入新数据而无需再次单击显示此 Modal Popup 的按钮。

我试着先这样称呼它:

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "ShowModalPopup(""" & Me.formModalButton.ID & """);", True)

但问题是当函数被调用时,我的 Modal Popup 在页面上尚不存在。因此,代码在

var modal = $find('myModal');

所以,我发现了另一种方式,它几乎完美地工作。

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowModalPopup(""" & Me.formModalButton.ID & """)};", True)

模态显示在我想要的页面加载上,但问题是如果我单击页面上的任何其他按钮,模态弹出窗口也会再次出现。

示例:我有另一个用于删除数据的 Modal Popup,当我单击按钮时,两个 Modal 都出现了,这并不酷。

有没有人知道如何解决这个问题或更好的方法?

PS我没有调用模态弹出服务器端,因为页面中存在javascript函数,所以我不想在RegisterStartupScript中创建这个函数的副本。

谢谢你的时间。

4

2 回答 2

2

使用下面的代码片段

//Declares gloabal variable
ClientScript.RegisterStartupScript(Page.GetType(),"vardeclaration","var reloadModal;",true);

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(

function() 
{
   reloadModal = function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """);};
   Sys.Application.add_init(reloadModal);
}
);", True)

这将允许您使用

function cancelClick()
{
   Sys.application.remove_init(reloadModal);
}
于 2009-02-12T16:23:10.410 回答
2

最后,我找到了解决当前问题的方法。

我仍在使用 ClientScript.Resgister[...] 但这次我还更改了取消按钮的 OnClientClick Javascript 函数。

因此,当这个人选择“保存并添加新”功能时,当页面重新加载并且模式再次显示时,如果他单击取消,我会回发到服务器只是为了重新加载页面并解决那些奇怪的行为。

我还认为,由于我的代码中的更新面板不同,问题可能存在,但我需要它们来使 Modal Popup Extender 工作。

无论如何,我发现它甚至不能在 Opera 和 Safari 中工作,而是整个事情(Ajax 控制工具包 - 模态弹出扩展器)。

这是一个机会,这里的公司不关心其他人,并且官方只支持 IE。就我而言,我想让它至少在 FF 和 Chrome 中也能正常工作。

ClientScript.RegisterStartupScript(Page.GetType(), "ModalPopup", "Sys.Application.add_load(function() {ShowAddModalPopup(""" & Me.imgAdd.ID & """)});", True)
                btnCancel.OnClientClick = "resetDefaultValue();__doPostBack('" & btnCancel.ID & "','onclick')"

所以有代码,在FF中也出现另一个错误,

Sys.WebForms.PageRequestManagerServerErrorException:处理服务器上的请求时发生未知错误。从服务器返回的状态码是:0

我找到了这个解决方法,它不是最好的,但我为此浪费了足够多的时间......

ClientScript.RegisterStartupScript(Page.GetType(), "WorkAroundFF", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); function endRequest(sender, args) { /* Check to see if there's an error on this request.*/ if (args.get_error() != undefined) { $get('Error').style.visibility = ""visible""; /* Let the framework know that the error is handled, so it doesn't throw the JavaScript*/ alert. args.set_errorHandled(true); } }", True)

因此,感谢您的帮助 Ramesh,如果不是我的更新面板,我很确定您的解决方案会起作用。

希望可以帮助别人。

于 2009-02-13T15:32:10.133 回答