{
}
-
[DefaultValue ("")]
- [WebSysDescription("")]
- [WebCategory("Action")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [WebSysDescription("")]
+ [WebCategory("Action")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
#if NET_2_0
- [UrlProperty]
+ [UrlProperty]
#endif
- public string HRef {
+ public string HRef {
get {
string s = Attributes ["href"];
return (s == null) ? String.Empty : s;
}
set {
- if (value == null || value == String.Empty) {
+ if (value == null || value.Length == 0) {
Attributes.Remove ("href");
} else {
Attributes ["href"] = value;
}
[DefaultValue ("")]
- [WebSysDescription("")]
- [WebCategory("Navigation")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public string Name {
+ [WebSysDescription("")]
+ [WebCategory("Navigation")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public string Name {
get {
string s = Attributes ["name"];
return (s == null) ? String.Empty : s;
}
set {
- if (value == null)
+ if (value == null || value.Length == 0)
Attributes.Remove ("name");
else
Attributes ["name"] = value;
}
[DefaultValue ("")]
- [WebSysDescription("")]
- [WebCategory("Navigation")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- public string Target {
+ [WebSysDescription("")]
+ [WebCategory("Navigation")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public string Target {
get {
string s = Attributes ["target"];
return (s == null) ? String.Empty : s;
}
set {
- if (value == null)
+ if (value == null || value.Length == 0)
Attributes.Remove ("target");
else
Attributes ["target"] = value;
}
[DefaultValue ("")]
- [WebSysDescription("")]
- [WebCategory("Appearance")]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ [WebSysDescription("")]
+ [WebCategory("Appearance")]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
#if NET_2_0
- [Localizable (true)]
+ [Localizable (true)]
#endif
- public string Title {
+ public string Title {
get {
string s = Attributes ["title"];
return (s == null) ? String.Empty : s;
}
set {
- if (value == null)
+ if (value == null || value.Length == 0)
Attributes.Remove ("title");
else
Attributes ["title"] = value;
#if NET_2_0
[DefaultValue (true)]
- public virtual bool CausesValidation {
+ public virtual bool CausesValidation {
get {
return ViewState.GetBool ("CausesValidation", true);
}
}
[DefaultValue ("")]
- public virtual string ValidationGroup {
+ public virtual string ValidationGroup {
get {
return ViewState.GetString ("ValidationGroup", String.Empty);
}
#if NET_2_0
protected internal
#else
- protected
+ protected
#endif
- override void OnPreRender (EventArgs e)
+ override void OnPreRender (EventArgs e)
{
base.OnPreRender (e);
}
protected override void RenderAttributes (HtmlTextWriter writer)
{
- string target = Attributes ["target"];
- if ((target == null) || (target.Length == 0))
- Attributes.Remove("target");
-
// we don't want to render the "user" URL, so we either render:
EventHandler serverClick = (EventHandler) Events [serverClickEvent];
if (serverClick != null) {
#endif
} else {
string hr = HRef;
- if (hr != "")
+ if (hr != string.Empty)
#if TARGET_J2EE
// For J2EE portlets we need to genreate a render URL.
- HRef = ResolveClientUrl (hr, String.Compare (target, "_blank", StringComparison.InvariantCultureIgnoreCase) != 0);
+ HRef = ResolveClientUrl (hr, String.Compare (Target, "_blank", StringComparison.InvariantCultureIgnoreCase) != 0);
#else
- HRef = ResolveClientUrl (hr);
+ HRef = ResolveClientUrl (hr);
#endif
}
// nor is the property available after rendering
Attributes.Remove ("href");
}
+
#if NET_2_0
protected virtual void RaisePostBackEvent (string eventArgument)
{
OnServerClick (EventArgs.Empty);
}
- PostBackOptions GetPostBackOptions () {
+ PostBackOptions GetPostBackOptions ()
+ {
PostBackOptions options = new PostBackOptions (this);
options.ValidationGroup = null;
options.ActionUrl = null;
- options.Argument = "";
+ options.Argument = string.Empty;
options.RequiresJavaScriptProtocol = true;
options.ClientSubmit = true;
options.PerformValidation = CausesValidation && Page != null && Page.AreValidatorsUplevel (ValidationGroup);
#endif
}
-
[WebSysDescription("")]
- [WebCategory("Action")]
- public event EventHandler ServerClick {
+ [WebCategory("Action")]
+ public event EventHandler ServerClick {
add { Events.AddHandler (serverClickEvent, value); }
remove { Events.RemoveHandler (serverClickEvent, value); }
}
Assert.AreEqual (" href=\"*1*\" name=\"*2*\" target=\"*3*\" title=\"*4*\"", writer.InnerWriter.ToString (), "HRef is back");
}
+ [Test]
+ public void RenderAttributes_HRef_Empty ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = string.Empty;
+ a.Name = "*2*";
+ a.Target = "*3*";
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" name=\"*2*\" target=\"*3*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_HRef_Null ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = null;
+ a.Name = "*2*";
+ a.Target = "*3*";
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" name=\"*2*\" target=\"*3*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Name_Empty ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = string.Empty;
+ a.Target = "*3*";
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" target=\"*3*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Name_Null ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = null;
+ a.Target = "*3*";
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" target=\"*3*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Target_Empty ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = "*2*";
+ a.Target = string.Empty;
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" name=\"*2*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Target_Null ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = "*2*";
+ a.Target = null;
+ a.Title = "*4*";
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" name=\"*2*\" title=\"*4*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Title_Empty ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = "*2*";
+ a.Target = "*3*";
+ a.Title = string.Empty;
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" name=\"*2*\" target=\"*3*\"", writer.InnerWriter.ToString (), "#3");
+ }
+
+ [Test]
+ public void RenderAttributes_Title_Null ()
+ {
+ TestHtmlAnchor a = new TestHtmlAnchor ();
+ Assert.AreEqual (0, a.Attributes.Count, "#1");
+ a.HRef = "*1*";
+ a.Name = "*2*";
+ a.Target = "*3*";
+ a.Title = null;
+ Assert.AreEqual (3, a.Attributes.Count, "#2");
+
+ HtmlTextWriter writer = a.GetWriter ();
+ Assert.AreEqual (" href=\"*1*\" name=\"*2*\" target=\"*3*\"", writer.InnerWriter.ToString (), "#3");
+ }
private bool serverClick;
private void ServerClick (object sender, EventArgs e)