views:

20

answers:

1

I have a custom UserControl (inherits System.Web.UI.UserControl) with this property, which should be set to a URL on the site that you want to link to:

 [DefaultValue("~/NewsItem.aspx"), UrlProperty("*.aspx")]
 public string InternalItemViewUrl
 {
  get { return _internalItemViewUrl; }
  set { _internalItemViewUrl = value; }
 }

The control will present the URL picker drop-down correctly, but if you select a URL from the list, it does not change it to a site-relative "~/foo.aspx" link, like HyperLink does, but instead only gets "foo.aspx" which does not work (the control is in /controls and the page obviously is not). If you scroll all the way down and use "Pick URL..." which opens the full pop-up window, a page selected in that dialog does get converted to "~/foo.aspx"

Am I missing something obvious here to make this work?

A: 

Check out the attributes on the HyperLink, especially the [Editor] attribute.

[DefaultValue(""),
 WebSysDescription("HyperLink_NavigateUrl"),
 UrlProperty, Bindable(true), WebCategory("Navigation"), 
 Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
kbrimington
WebCategory and WebSysDescription are internal to System.Web. My first thought was to reflector System.Web.UI.WebControls.HyperLink.NavigateUrl too. I can set it as such, but it still behaves the same way, no ~.<code> [DefaultValue(""), UrlProperty, Bindable(true), Editor("System.Web.UI.Design.UrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]</code>
Carl Bussema
Hmmm. I thought for certain the Editor attribute would square things away for you. As an aside, you can swap `WebSysDescription` for `Description` and `WebCategory` for `Category`, but those attributes aren't the source or solution of the problem.
kbrimington
Yeah, it's weird. If I select the item directly from the intellisense drop-down, no tilde. If I scroll down to "Pick Url..." and use that dialog, it works normally. For now I'm just removing the UrlProperty attribute, because I figure you're more likely to type the ~ if you have to do it manually than if you get intellisense, pick a file, and it doesn't get corrected.
Carl Bussema