单击按钮时创建新的弹出窗口

时间:2013-07-29 06:19:05

标签: c# popup

ClientScript.RegisterStartupScript(this.GetType(), 
                                   "newWindow",
                                    String.Format("<script>window.open('{0}');</script>",url));

当我点击按钮时,我在新窗口中为Pop UP报告编写此代码,它显示“报告已成功创建”但新窗口未打开。

2 个答案:

答案 0 :(得分:0)

假设您调用了弹出窗口类“PopupWindow”。您通过右键单击项目资源管理器中的项目并选择“添加新Windows窗体”来创建它。然后你添加了一个文本框和一个“Ok”-Button。

您还在表单中添加了一个属性,以便以后可以访问用户在文本框中输入的数据。

public class PopupWindow
{
    public string EnteredText
    {
        get
        {
            return( textBox.Text );
        }
    }
}

现在你使用这样的新类:

PopupWindow popup = new PopupWindow();

popup.ShowDialog();

string userEnteredText = popup.EnteredText;

popup.Dispose();

答案 1 :(得分:0)

这段代码在语法上是正确的,我没有看到任何理由不应该这样做。

很少要检查

  • 网址格式正确
  • 检查是否有弹出窗口阻止程序。
  • 尚未使用键名“newWindow”。

尝试将下面的代码放在Page_load方法中。

ClientScript.RegisterStartupScript(this.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", "http://www.google.com"));

如果上述代码最有效,那么您应该确保Url的值格式正确。