我在我的项目中使用VS2010 Express版。
我创建了一个注册表单,其中包含"提交"按钮,将打开新窗口(子窗口)。
它包含aspx按钮()。
子窗口再次包含一个由我们填写的表单,在单击“保存”按钮后,该表单将被保存,如果我们关闭子窗口,则在保存之后,将提交注册表单。
SetJavaScript();
if (Session["IsSuccess"] != null)
if (Session["IsSuccess"].ToString().ToLower() == "success")
TextBox1.Text = Session["IsSuccess"].ToString();
if (ddlTicketType.SelectedValue.ToString().ToLower() == "cr")
btnSubmit.Attributes.Add("OnClick", "OpenChild(); ");
if (ddlTicketType.SelectedValue.ToString().ToLower() == "pr")
由于window.showmodaldialog无法处理chrome。我也使用了window.open但它也没有正常工作,因为它打开子表单并在关闭它之后出现错误消息的注册表单"请填写表单"。 下面是在页面加载时调用的javascript代码。
private void SetJavaScript()
{
string str_Script = "";
str_Script += "<script type='text/javascript' language='javascript'>";
str_Script += "function OpenChild() ";
str_Script += "{ CheckValidation();";
str_Script += "var varx = document.getElementById('TextBox1').value;";
str_Script += "if (varx== 'yes'){";
str_Script += "var ParmA = '2';";
str_Script += "var MyArgs = new Array(ParmA);";
str_Script += "if (ParmA=='2'){";
str_Script += "var WinSettings = 'center:yes;resizable:yes;dialogheight:800px;dialogwidth:1000px';";
str_Script += "MyArgs = window.showModalDialog('user/cr1.aspx', MyArgs, WinSettings);";
str_Script += "if (MyArgs == null)";
str_Script += "{";
str_Script += "}";
str_Script += "else";
str_Script += "{";
str_Script += "document.getElementById('TextBox1').value =MyArgs[0].toString();";
str_Script += "}";
str_Script += "}}";
str_Script += "</script> ";
this.Page.RegisterStartupScript("Reconnect", str_Script);
请帮助我让它再次正常工作,因为它在Chrome更新之前工作得非常好。 请让我知道任何可以解决它的好方法。
答案 0 :(得分:3)
我们在许多传统的asp应用程序上遇到此问题。我找到了至少3种不同的方法,但我认为这是一个更简单的方法,我认为这是一个可能的答案。它非常适合修复经典的asp页面,但也适用于.Net环境。这是方法的伪代码:
在调用表单中javascript:
def InitUi(self):
# ...
# Add a delay timer, set it up and stop it
self.delay_slider_evt = wx.CallLater(2000, self.delayed_event)
self.delay_slider_evt.Stop()
def OnSliderScroll(self, e):
# if delay timer does not run, start it, either restart it
if not self.delay_slider_evt.IsRunning():
self.delay_slider_evt.Start(2000)
else:
self.delay_slider_evt.Restart(2000)
def delayed_event(self):
#substitute for the actual delayed process.
self.counter += 1
print self.counter
然后在子页面中,我准备好了一个文件,知道是关闭窗口模式还是调用开启器的功能。 &#34;揭幕战&#34;是打开弹出窗口的页面。对于.net,我建议回帖设置一个隐藏变量,让页面知道它已经完成。
var chrome_pop_up_window = null; //global for next few functions
function uploadChromeFinished(parameters) {
//do something with parameters
if(chrome_pop_up_window != null) {
chrome_pop_up_window.close();
chrome_pop_up_window = null;
}
}
function OpenChild() {
if(!window.showModalDialog)
chrome_pop_up_window = window.open(url, "_blank", other_settings);
else {
var result = showModalDialog(...);
}
}
然后最终结果是弹出窗口无论是在Chrome还是IE中都会被打开,并且孩子可以在关闭Chrome或IE时将信息传回给父母,尽管在Chrome的情况下,父母实际关闭了孩子它从子节点获取参数值。无需插件或json。
答案 1 :(得分:2)
正如您可以阅读here,不推荐使用Window.showModalDialog(),Chrome不再支持版本37,并且已从版本43中完全删除。
使用Bootstrap Modal代替,或者如果代价太贵,请尝试使用library,这是一个window.showModalDialog polyfill