ASP.NET HyperLink 而不是 LinkBut​​ton - 如何避免图像周围的边框?

发布于 2024-09-25 20:38:26 字数 1253 浏览 1 评论 0原文

我有一个 ASP.NET 网站,其中包含一些 ImageButton 控件,这些控件会导致用于将产品列表过滤到某些产品组的回发。

ImageButton 的创建方式如下:

ImageButton _myImageButton = new ImageButton();
_myImageButton.ImageUrl = PicturePath + PictureName;
_myImageButton.Attributes.Add("border", "0");
_myImageButton.OnClick += handleImageButtonClick();
Controls.Add(_myImageButton);

现在我正在转向 ASP.NET 4.0,使用 SEO 友好的路径,例如 /products/category/item,并且我正在使用 Webforms 的路由将 URL 映射到 Webforms 。在此过程中,我想用显示图像的超链接控件替换图像按钮,以便我可以将导航 URL 与每个图像相关联。

我正在创建新的图像超链接,如下所示:

HyperLink _myImageLink = new HyperLink();
_myImageLink.ImageUrl = PicturePath + PictureName;
_myImageLink.NavigateUrl = "/products/category/" + itemName;
_myImageLink.Attributes.Add("border", "0");
Controls.Add(_myImageLink);

我面临的大问题:ImageButton 用于在 border="0" 属性上放置 border="0" 属性HTML 中的 > 标记以避免图像周围出现边框。但是如何使用超链接控件达到相同的结果?

在当前设置下, border="0" 会卡在 标签上 - 这并不完全是我想要的想要/需要。

有什么想法吗?想法??我已经尝试过 HyperLink 类的 .BorderStyle.BorderWidth 元素 - 似乎对我不起作用(我仍然看到边框围绕我的形象)。

我缺少什么?我怎样才能实现我的目标?

I have an ASP.NET web site which contains some ImageButton controls that cause postbacks used to filter a list of products to certain groups of products.

The ImageButton was created something like this:

ImageButton _myImageButton = new ImageButton();
_myImageButton.ImageUrl = PicturePath + PictureName;
_myImageButton.Attributes.Add("border", "0");
_myImageButton.OnClick += handleImageButtonClick();
Controls.Add(_myImageButton);

Now I am moving to ASP.NET 4.0 with SEO-friendly paths like /products/category/item, and I'm using routing with Webforms to map URL's to webforms. In the process, I want to replace my image buttons with hyperlink controls showing the image, so that I can associate a navigational URL with each image.

I'm creating my new image hyperlink something like this:

HyperLink _myImageLink = new HyperLink();
_myImageLink.ImageUrl = PicturePath + PictureName;
_myImageLink.NavigateUrl = "/products/category/" + itemName;
_myImageLink.Attributes.Add("border", "0");
Controls.Add(_myImageLink);

The big problem I'm facing: the ImageButton used to put a border="0" attribute on the <img> tag in HTML to avoid a border around the image. But how can I achieve the same result using the hyper link control??

With the current setup, the border="0" gets stuck onto the <a href="...."> tag - and that's not exactly what I want / need.

Any ideas?? Thoughts?? I already tried the .BorderStyle and .BorderWidth elements of the HyperLink class - doesn't seem to work for me (I still see a border around my image).

What am I missing?? How can I achieve my goal??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

待"谢繁草 2024-10-02 20:38:26

该属性不会自动插入到 ASP.NET 4.0 中,因为它已被弃用。您应该使用 CSS 将相关的 img 标记设置为没有边框。一种可能的建议是将其设置在 a 标记内的 img 标记上:

a img{
  border: none;
}

That attribute is not automatically inserted in ASP.NET 4.0 because it's deprecated; you should use CSS instead to set the img tag in question not to have a border. One possible suggestion would be to set it on img tags within a tags:

a img{
  border: none;
}
咆哮 2024-10-02 20:38:26

好像你不知道边界的原因。

这只是来自 URL

一个简单的 css 可以解决这个问题:

a {
  text-decoration: none;
}

或者您可以在 的样式中设置 text-decoration: none;图片链接

myImageLink.Attributes.Add("style", "text-decoration: none");

It seems as if you dont know the reason of the border.

this is just from the URL <a>

a simple css could fix that:

a {
  text-decoration: none;
}

or you could just set text-decoration: none; in your style of your imageLink

myImageLink.Attributes.Add("style", "text-decoration: none");
胡渣熟男 2024-10-02 20:38:26

与其设置超链接的 ImageUrl 属性,为什么不将图像添加为超链接的子项,这样您仍然可以在其上设置所需的所有属性。

Instead of setting the ImageUrl property of the hyperlink, why don't you add the image as a child of the hyperlink, that way you can still set all the properties you want on it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文