如何创建包含图像和内容的链接文本?
我需要为具有图像和图像的 ASP.NET 页面创建一个链接。文本,单击该文本将触发网络服务器上的事件。
链接应如下所示:
这是链接的 HTML,如果我无法使用 ASP.NET:
<a id='PdfLink' href='#'>
<img src="App_Themes/.../Images/PDF.gif" alt="Click for fact sheet PDF"/>
<span>Latest Performance</span>
</a>
问题是我希望能够单击此按钮并触发服务器端事件,但我不知道是否可以使用普通的旧 HTML 控件来做到这一点。
使用 ASP.NET,我可以看到有各种控件,例如 ImageButton 和 ImageButton。超链接,但我不知道如何拥有超链接和作为同一可点击控件的一部分的 ImageButton。
对我来说,获取与绑定到服务器端功能的图像类似的链接的最佳方式是什么?
I need to create a link for an ASP.NET page that has an image & text, which when clicked will trigger an event on the webserver.
This is what the link should look like:
This is the HTML for what the link would look like if I wasn't working with ASP.NET:
<a id='PdfLink' href='#'>
<img src="App_Themes/.../Images/PDF.gif" alt="Click for fact sheet PDF"/>
<span>Latest Performance</span>
</a>
The problem with this is that I want to be able to click this and trigger an server-side event, but I don't know if I can do that with plain old HTML controls.
With ASP.NET I can see that there are various controls such as ImageButton & HyperLink but I don't see how I can have a Hyperlink & an ImageButton as part of the same clickable control.
What's the best way for me to get a link similar to the image that is bound to server-side functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不会通过使用混合控件来做到这一点。
我将使用
控件然后我将使用 CssClass“最新性能”来设置链接的样式。
例如,
您必须调整样式以适应您的需要,但这基本上看起来与您需要的完全相同。它还可以使您的代码保持干净,并分离出样式。
I wouldn't do this by using a mixture of controls.
I would use a
<asp:LinkButton>
controlThen I would use the CssClass "latest-performance" to style up the link.
e.g.
You will have to tweek the style to fit with what you need, but this will basically look exactly the same as what you need. It also keeps your code clean, and separates out the style.
你可以像..
You can do like..
要在 ASP .NET 中执行您想要执行的操作,您需要执行以下操作:
然后,您可以编写自定义服务器或用户控件来封装这些控件,以便它们仅公开您希望设置一次的属性,例如单击时的事件。
To do what you want to do in ASP .NET you'd need to do something like this:
You could then write a custom server or user control to encapsulate those controls so they only expose the properties you wish to set once, such as the event when clicked.
这样做的好处是 asp:Literal 是轻量级的。如果需要,您还可以通过在后面的代码中使用literalID.Text 以编程方式更改 asp:Literal 内的文本。我喜欢这个,因为您只需要在简单标签内使用单个控件。您可以给它任何您想要的 href、目标和 img。希望这有帮助。
The benefit of this is that asp:Literal is lightweight. You can also programmatically change the text inside the asp:Literal, by using literalID.Text in the code behind, if you need to. I like this because you only need to use a single control inside of a simple tag. You can give it whichever href, target, and img you want. Hope this helps.
你可以这样做,这个答案是正确的。
You can do like this, this answer is correct.