1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
namespace MonNameSpace
{
[DefaultProperty("Text"),
ToolboxData("<{0}:PopupButton runat=server Text='Open a popup'></{0}:PopupButton>")]
public class PopupButton : System.Web.UI.WebControls.Button
{
private int m_height;
private int m_width;
private String m_url;
public enum YesNoType { no, yes }
private YesNoType m_status;
private YesNoType m_resizable;
private YesNoType m_scrollbars;
private YesNoType m_toolbar;
private YesNoType m_location;
private YesNoType m_menubar;
private YesNoType m_modal;
[Bindable(true),
Category("Appearance"), Description("The URL that will be opened in the popup window")]
public string PopupURL
{
get
{
if (Page != null && (Page.Site == null || !Page.Site.DesignMode))
{
return Page.Response.ApplyAppPathModifier(m_url);
}
else
{
return m_url;
}
}
set
{
m_url = value;
}
}
[Bindable(true),
Category("Appearance"), Description("This sets the height of the new window in pixels.")]
public int PopupHeight
{
get { return m_height; }
set { m_height = value; }
}
[Bindable(true),
Category("Appearance"), Description("The width of the popup window")]
public int PopupWidth
{
get { return m_width; }
set { m_width = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes, the new window will have the standard browser status bar at the bottom.")]
public YesNoType Status
{
get { return m_status; }
set { m_status = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes this allows the resizing of the new window by the user.")]
public YesNoType Resizable
{
get { return m_resizable; }
set { m_resizable = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes the new window is created with the standard horizontal and vertical scrollbars, where needed")]
public YesNoType Scrollbars
{
get { return m_scrollbars; }
set { m_scrollbars = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes the new window will have the standard browser tool bar (Back, Forward, etc.).")]
public YesNoType Toolbar
{
get { return m_toolbar; }
set { m_toolbar = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes, this creates a new browser window with the standard menu bar (File, Edit, View, etc.).")]
public YesNoType Menubar
{
get { return m_menubar; }
set { m_menubar = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes, this creates the standard Location entry feild in the new browser window.")]
public YesNoType Location
{
get { return m_location; }
set { m_location = value; }
}
[Bindable(true),
Category("Appearance"), Description("When set to yes, this creates a modal popup window.")]
public YesNoType Modal
{
get { return m_modal; }
set { m_modal = value; }
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
String atts = "";
if (m_modal == YesNoType.yes)
atts = "javascript:window.showModalDialog('" + m_url + "','','dialogHeight:" + m_height + "px, dialogWidth:" + m_width + "px, center:yes');";
else
atts = "javascript:window.open('" + PopupURL + "','','height=" + m_height + ", width=" + m_width + ", status=" + m_status.ToString() + ", resizable=" + m_resizable.ToString() + ", scrollbars=" + m_scrollbars.ToString() + ", toolbar=" + m_toolbar.ToString() + ",location=" + m_location.ToString() + ",menubar=" + m_menubar.ToString() + "');";
writer.AddAttribute("onClick", atts);
base.AddAttributesToRender(writer);
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.CausesValidation = false;
this.UseSubmitBehavior = false;
}
}
} |
Partager