【问题标题】:show Select URL box for ClickImageURL in Custom ImageButton在自定义 ImageButton 中显示 ClickImageURL 的选择 URL 框
【发布时间】:2010-02-26 09:13:43
【问题描述】:

我正在制作一个自定义 ImageButton 控件,它可以通过添加 onmouseup 和 onmousedown javascript 代码来更改图像 URL 来显示按钮单击效果。我已经构建了控件,它有一个 ClickImageUrl 来设置单击按钮时要显示的图像的 URL..

我想知道有什么方法可以为我的控件添加一个选择 URL 对话框,就像 ImageUrl 的对话框一样。有可能吗???如果是这样,我将如何去做...??

任何帮助将不胜感激。

编辑:根据 Arther 的回答,当我使用它来设置 ClickImageUrl 时,我能够显示一个选择图像 URL 对话框,它显示设计器错误为:

错误渲染控制 发生未处理的异常 '~/images/7.jpg' 不能在属性'ClickImageUrl'上设置

它是否与 ImageUrl 冲突???

【问题讨论】:

  • 正确理解您的问题:您是在谈论 Visual Studio 中的设计器吗?不是关于运行时的“选择 URL”对话框?

标签: asp.net custom-controls imagebutton


【解决方案1】:

如果您谈论的是 VS 设计器,那么您必须使用以下属性来装饰您的属性:

public class CustomImageButton : System.Web.UI.WebControls.ImageButton
{
    [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    [UrlProperty]
    public string ClickImageUrl { get; set; }
}

【讨论】:

  • 非常感谢...就像一个魅力...但是当我使用它来设置 ClickImageUrl 时,它在设计器中显示错误..错误渲染控件..发生了未处理的异常“ ~/images/7.jpg" 不能在属性 ClickImageUrl 上设置...知道为什么会这样...???
  • 也是如何找到这个的..它是否记录在某个地方? bcoz似乎很难记住??
  • @Error: 也许你在你的 setter 中做一些工作,这可能会导致设计时错误。 @找出:简单:在代码中编写 ImageButton,然后右键单击 -> 转到定义。将显示 ImageButton 的定义。然后转到 ImageUrl 并展开 cmets 和属性 - 就是这样!
猜你喜欢
  • 2021-05-21
  • 1970-01-01
  • 2012-07-22
  • 1970-01-01
  • 2021-10-09
  • 1970-01-01
  • 1970-01-01
  • 2018-06-08
  • 1970-01-01
相关资源
最近更新 更多