Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

.net - Adding an image and text both in asp.net button

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Using CSS

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

enter image description here

<style type="text/css">
    .submit {
        border: 1px solid #563d7c;
        border-radius: 5px;
        color: white;
        padding: 5px 10px 5px 25px;
        background: url(https://i.stack.imgur.com/jDCI4.png) 
            left 3px top 5px no-repeat #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.

enter image description here

Use third party control like Telerik RadButton.

Last but not least if you want, you can implement a custom server control by yourself.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...