【问题标题】:How to create a pop up window when a button is clicked单击按钮时如何创建弹出窗口
【发布时间】:2015-01-06 15:05:50
【问题描述】:

这是我的按钮代码。我希望配置按钮在单击时显示一个弹出窗口。我已经查找并尝试了很多不同的代码,但它们都不起作用。我觉得我缺少一个关键组件,但我不确定那是什么。感谢帮助!

tr = new TableRow();
// Create the cell
tc = new TableCell();
tc.Width = Unit.Point(300);
tc.BorderWidth = 0;
tc.BorderStyle = BorderStyle.None;

Button ConfigButton = new Button();
ConfigButton.Text = "Configuration";
ConfigButton.Visible = true;

tc.Controls.Add(ConfigButton);
tr.Cells.Add(tc);
tbl.Controls.Add(tr);

【问题讨论】:

  • 如果您只想显示字符串消息,MessageBox 就足够了,为按钮的Click 事件添加处理程序并显示MessageBox
  • 弹出窗口中有什么?
  • 上一条评论说使用MessageBox,而你的问题说popupwindow。当我认为是 popupwindow 时,我在想你正在做 ASP.Net 并且你想要一个 javascript 解决方案。 MessageBox 听起来更像是 WinForm 和对话框。
  • 这是一个网站吗?它看起来像 WebForms 代码。
  • TableRow 在我看来像 asp.net

标签: c# asp.net button popupwindow


【解决方案1】:

Using JavaScript Along with ASP.NET 你将执行以下操作:

// when you create the button, you can add attributes
Button ConfigButton = new Button();

// this example will display alert dialog box
ConfigButton.Attributes.Add("onclick", "javascript:alert('ALERT ALERT!!!')");

// to get you popup windows
// you would use window.open with the BLANK target

ConfigButton.Text = "Configuration";
ConfigButton.Visible = true;

【讨论】:

    【解决方案2】:

    我建议考虑使用 AJAX 控制工具包 ModalPopupExtender。这是我在 ASP.NET 中用于弹出窗口的内容。

    这里是 AJAX 控件工具包示例网站的链接,展示了此控件的工作原理: http://www.ajaxcontroltoolkit.com/ModalPopup/ModalPopup.aspx

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      相关资源
      最近更新 更多