Language:

Easy PopUp-WebControl

Language: Deutsch
Programming Language: C#
Published by: Chris [not registered]
Last Update: 5/5/2006
Views: 855

Description

Shows a simple sample for a custom webcontrol which opens a popup window.

Code

1 /// <summary>The iPopUp Control: an easy way to create PopUps 2 /// without writing the Client 3 /// Javascript Code. </summary> 4 public class iPopUp : WebControl 5 { 6 /// <summary>Enables or Disables the Scrollbars in the 7 /// opening PopUp</summary> 8 public bool Scrollbars = false; 9 10 11 /// <summary>Enables or Disables the Menubar in the 12 /// opening PopUp</summary> 13 public bool Menubar = false; 14 15 16 /// <summary>Enables or Disables the Locationbar in the 17 /// opening PopUp</summary> 18 public bool Locationbar = false; 19 20 21 /// <summary>Enables or Disables the possibility to 22 /// Resize the opening PopUp</summary> 23 public bool Resizeable= false; 24 25 26 /// <summary>Enables or Disables the Statusbars in the 27 /// opening PopUp</summary> 28 public bool Statusbar = false; 29 30 31 /// <summary>Toggles Fullscreen mode on or off. Maybe 32 /// unsupported in some Browsers.</summary> 33 public bool Fullscreen = false; 34 35 36 /// <summary>Gets or Sets the Top (y) Position of the 37 /// new PopUp</summary> 38 public Unit Top = new Unit(); 39 40 41 /// <summary>Gets or Sets the Left (x) Position of the 42 /// new PopUp</summary> 43 public Unit Left = new Unit(); 44 45 46 private string text = ""; 47 48 49 /// <summary>Gets or Sets the Text which is displayed as 50 /// an Link to open the PopUp</summary> 51 public string Text 52 { 53 get { return text; } 54 set { text = value; } 55 } 56 57 58 /// <summary>Gets or Sets the URL to the Website which 59 /// will be opende inside the new PopUp</summary> 60 public string NavigateUrl 61 { 62 get 63 { 64 object obj = ViewState["NavigateUrl"]; 65 return (obj == null) ? String.Empty : 66 (string)obj; 67 } 68 set 69 { 70 ViewState["NavigateUrl"] = value; 71 } 72 } 73 74 75 /// <summary>Gets or Sets the URL to an Image which will 76 /// be displayed as an Link to open the PopUp</summary> 77 public string ImageUrl = ""; 78 79 80 /// <summary>Gets or Sets the Alternating Text (to the 81 /// ImageUrl Property) which will be displayed if 82 /// Images are disabled in the Browser.</summary> 83 public string AlternateText = ""; 84 85 86 /// <summary>Used to create the Control</summary> 87 protected override void OnLoad (EventArgs e) 88 { 89 StringBuilder Options = new StringBuilder(); 90 if (Fullscreen) 91 Options.Append("fullscreen = yes, "); 92 else Options.Append("fullscreen = no, "); 93 94 95 if (Scrollbars) 96 Options.Append("scrollbars = yes, "); 97 else Options.Append("scrollbars = no, "); 98 99 100 if (Menubar) 101 Options.Append("menubar = yes, "); 102 else 103 Options.Append("menubar = no, "); 104 105 106 if (Locationbar) 107 Options.Append("locationbar = yes, "); 108 else 109 Options.Append("locationbar = no, "); 110 111 112 if (Resizeable) 113 Options.Append("resizeable = yes, "); 114 else 115 Options.Append("resizeable = no, "); 116 117 118 if (Statusbar) 119 Options.Append("status = yes "); 120 else 121 Options.Append("status = no "); 122 123 124 if (!Left.IsEmpty) 125 Options.Append("left = " + Left.ToString() + ", "); 126 127 128 if (!Top.IsEmpty) 129 Options.Append("top = " + Top.ToString() + ", "); 130 131 132 if (!Width.IsEmpty) 133 Options.Append("width = " + Width.ToString() + ", "); 134 135 136 if (!Height.IsEmpty) 137 Options.Append("height = " + Height.ToString()); 138 139 140 StringBuilder myString = new 141 StringBuilder("<script language=\"Javascript\">"); 142 143 144 myString.Append("function PopUp_" + 145 this.ClientID + "() {"); 146 147 148 myString.Append(" window.open(\"" + 149 ViewState["NavigateUrl"] + "\",\"Bildermanager\", \"" + 150 Options.ToString() + "\")"); 151 152 153 myString.Append(" } </script"); 154 myString.Append(">"); 155 156 157 Page.RegisterClientScriptBlock("PopUp_" + 158 this.ClientID, myString.ToString()); 159 160 161 } 162 163 164 /// <summary>Used to create the Control</summary> 165 protected override void Render( HtmlTextWriter writer) 166 { 167 if (ImageUrl != string.Empty) 168 { 169 text = "<img src=\"" + ImageUrl + "\\" + 170 " alt=\"" + AlternateText + "\" border=\"0\">" + text; 171 } 172 writer.Write("<a target=\"_self\" href=\"javascript:PopUp_" 173 + this.ClientID + "()\">" + text + "</a>"); 174 } 175 }

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS