添加无论是在asp.net按钮的图像和文字是在、按钮、图像、文字

2023-09-04 01:18:52 作者:风吹裙摆pp凉

我要寻找一个解决方案,我可以添加图像和文本无论是在asp.net按钮。

I am looking for a solution where I will be able to add an image and text both in asp.net button.

 <asp:Button ID="Button1" runat="server" Text="Button"/> 

我只能够指定文字的按钮,但我怎么可以添加一个形象,以及它?

I am only able to specify text to the button, but how can I add an image as well to it?

推荐答案

在默认情况下,ASP .NET不有一个按钮,可以在同一时间呈现图像和文字。但是,您可以通过两种方式实现。

By default, ASP .Net doesn't have a button which can render both image and text at the same time. However, you can achieve in two ways.

我preFER CSS,因为它重量轻,你可以风格它任何你想要的。

I prefer CSS because it is light weight, and you can style it whatever you want.

<style type="text/css">
    .submit {
        border: 1px solid #563d7c;
        border-radius: 5px;
        color: white;
        padding: 5px 10px 5px 25px;
        background-image: url(https://cdn.sstatic.net/stackoverflow/img/sprites.png?v=6);
        background-position-y: 465px;
        background-position-x: 5px;
        background-color: #563d7c;
    }
</style>

<asp:Button runat="server" ID="Button1" Text="Submit" CssClass="submit"/>

第三方控制

它的工作原理正确的开箱即用。但是,你不能轻易改变自己的风格。

Third Party Control

It works right out of the box. However, you cannot change their style easily.

使用如的Telerik RadButton 第三方控制。

最后但并非最不重要的,如果你愿意,你可以实现自己的自定义服务器控件。的