0

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.

3
  • 1
    You should create custom buttons which inherits Button only if you want to put additional server side functionality. If you want to change only design parts use css/jquery(or other javascript libraries) add put proper CssClass for the button. Commented Nov 22, 2016 at 22:14
  • @mybirthname's solution is the way to go. Commented Nov 23, 2016 at 0:13
  • Thank you very much. I see an example that uses CSS for an answer and I will experiment with that. It looks like user or custom server controls could work, but at the same time it looks more complicated. Thanks for pointing me in the right direction. Commented Nov 24, 2016 at 3:04

2 Answers 2

2

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,

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.sstatic.net/jDCI4.png) 
            left 3px top 5px no-repeat #563d7c;
    }
</style>

<asp:Button runat="server" ID="Button1" Text="Submit" CssClass="submit" />
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I will play around with this and see how it goes. The more experience I can get using CSS the better.
1

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

1 Comment

Thanks for your input on the User and Custom controls. I will play around with this solution and the CSS. The more I can learn, the better of a developer I will be come. Thank you for your input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.