fokz8 fokz8 - 13 days ago 4
ASP.NET (C#) Question

How to select and get color in asp.net

As there is no integrated attribute for color in asp.net (atleast i haven't found it), i wonder, how do you guys select color?

Let's say i want to create a drawing using bitmap and i want to get background color from the user who selects it using the application.

I've done some code behind, but thing doesn't work, as i manually type in colors like #000 or #fff (using textbox)

app.aspx

<label>
<span>Background color</span>
<asp:TextBox ID="inp_bgColor" Width="125px" runat="server"></asp:TextBox>
</label><span style="color:red"><asp:Literal ID="error_bg" runat="server"></asp:Literal></span><br /><br />


and app.aspx.cs

Color txtClr = Color.FromName(inp_bgColor.Text);


I've noticed that System.Drawing.Color is type of ARGB color, so how do i do this?

Thanks!

Answer

You can use hex colors like this:

string hex = "#FF3FF3";
Color _color = System.Drawing.ColorTranslator.FromHtml(hex);
Comments