简体   繁体   中英

Custom buttons for Web Forms in asp.net

I would like to make some custom buttons for a website I am writing in asp.net. I am having a hard time figuring out what would be the best way to go.

For these buttons, I would like to design their looks. Shapes other than rectangles is what I am going for. I also want these buttons to behave like a normal button would. Lets say the normal state version of the button is red, then when I click on the button it turns yellow, and finally when I release ( mouse button up ), it goes back to red. I would also like the clickable region be in the same shape of the button.

I have looked at ImageButtons and this doesn't quite fit what I want it to do. I have looked at User Controls and Custom Controls but I don't know if this is quite what I want either. In school, we didn't really go over these features in either of my C sharp class or asp.net web development class. Most stuff that seems to fit what I want are demos and examples in winforms, not necessarily in webforms.

What is the best way to go to try and accomplish this? Is User Control the way to go? Or is there a more elegant way to accomplish this? Any advice is greatly appreciated. I don't want code, I just want to know which way to go that you guys would think would be easiest.

Thank you.

As for me, I won't implement User Control just to style button. Instead, I'll use CSS to style them, because CSS is light weight and easy to maintain.

For example,

在此处输入图片说明

<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" />

User or Custom controls are the way to go. You can define the HTML, CSS, Javascript, rendering, everything that your control needs.

User controls are .ascx files that you can implement in your code behind. They are easy and lightweight but not good for large projects.

Custom controls are compiled and if desired you can drag and drop them in your form(s). These take more time but you can control the rendering and they work well in large projects.

You can read more here:

https://msdn.microsoft.com/en-us/library/aa651710%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM