You must Sign In to post a response.
  • Category: ASP.NET

    Using color pickers in asp.net

    hi friends,
    1) how to insert the selected colors using color pickar in asp.net.
    2)display the colors in back end to front end.
    please solve it.
  • #763012
    Hello Sadiq,

    I am not getting you what you want to do actually.

    Insert the selected colors using color picker but which colors and where you want to insert it.

    As per my understanding To display colors from back-end to front-end. Refer the below code :

    <asp:Label ID="Label1" runat="server" Text="www.dotnetspider.com"
    Font-Names="Segoe UI" Font-Size="Medium" Font-Strikeout="False" ForeColor="Red"></asp:Label>

    using System.Drawing;

    protected void Page_Load(object sender, EventArgs e)
    {
    Label1.ForeColor = Color.RoyalBlue;
    }

    Hope this will help you.

    Response to this thread for more clarified answer. So that according to your requirement. We can help you in better way.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763016
    hi friends,
    please check out the below given screen shot.in this i'am selecting the color in color pikker and insert the value.at a time i want show the only color in another textbox.

    Delete Attachment

  • #763018
    Hello Sadiq,

    I am using obout's controls for my ASP.NET Applications.

    You can download it from the below link :

    https://www.obout.com/inc/suite_download/default.aspx?type=20


    Refer the below sample code i have made it for you :

    html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>
    <script type="text/JavaScript">
    function onClientOpen(sender, args) {
    sender.setColor(sender.get_targetElement().style.backgroundColor);
    }
    </script>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
    <asp:TextBox ID="TextBox1" runat="server" ReadOnly="true" style="cursor: pointer; background-color: #FFFFFF"></asp:TextBox>
    <obout:ColorPickerExtender ID="ColorPickerExtender1" runat="server" OnClientOpen="onClientOpen" OnColorPostBack="color_postback" AutoPostBack="true" TargetProperty="style.backgroundColor"
    PopupButtonID="TextBox1" TargetControlID="TextBox1"></obout:ColorPickerExtender>
    </div>
    </form>
    </body>
    </html>

    protected void color_postback(object sender, Obout.Ajax.UI.ColorPicker.ColorPostBackEventArgs e)
    {
    TextBox1.Style[HtmlTextWriterStyle.BackgroundColor] = e.Color;
    }

    See the attached image. It's an output i have got using above mentioned code.

    Hope this is what you are looking for.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763019
    thank you response,but i want bring the color from db to textbox.
    protected void Button1_Click(object sender, EventArgs e)
    {
    SqlConnection con = new SqlConnection("Data Source=sadiq-pc;Initial Catalog=sadiqsql;User ID=sa;Password=sadiq");
    con.Open();
    string s = "insert into color values('" + TextBox1.Text + "')";
    SqlCommand cmd = new SqlCommand(s,con);
    int i=cmd.ExecuteNonQuery();

    if (i == 1)
    {
    string s1 = "select name from color"; //want color name
    SqlDataAdapter da = new SqlDataAdapter(s1,con);
    DataSet ds = new DataSet();
    da.Fill(ds, "color");
    //TextBox2.Text =
    TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(ds.Tables[0].ToString()); //show error
    }
    con.Close();
    }

  • #763020
    Actually in ds.table[0].tostring() pass the color name like "red" or "fff394" how i can do it

  • #763022
    Hello Sadiq,

    Change this part of coding :

    if (i == 1)
    {
    string s1 = "select name from color";
    SqlCommand da = new SqlCommand(s1,con);
    SqlDataReader dr = da.ExecuteReader();
    if(dr.HasRows)
    {
    dr.Read();
    TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml(dr[0].ToString());
    dr.Dispose();
    }
    }

    This code will change the background color of TextBox2 based on the value you get from database.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763024
    thank you for response but it shows the error "7033FF is not a valid value for Int32."

  • #763025
    thank you i got the solution just add the "#" for that value it show the result.but how to add the # for this value.actually in selecting the color in color pikker it gives the value without "#".
    how i can add this.

  • #763026
    Hello Sadiq,

    You have to add it manually. Because you will get the all the values in Hexa Decimal. So you can add it like

    TextBox2.BackColor = System.Drawing.ColorTranslator.FromHtml("#" + dr[0].ToString());

    Hope this will work for you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763029

  • #763031
    Hi Sadiq,

    Multiple colors for same textbox is not possible. But if you are looking for multiple textboxes with different different color than it is possible.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763032
    Thank u it's working

    Now one more doubt.if i select the color from color pikker at time different colors can add the multiple textboxs with multiple colors.

  • #763033
    ya i'am asking the same multiple textboxes with different different color

  • #763035
    Hello Sadiq,

    Just add this lines of tag :

    <asp:TextBox ID="TextBox2" runat="server" ReadOnly="true" style="cursor: pointer; background-color: #FFFFFF"></asp:TextBox>
    <obout:ColorPickerExtender ID="ColorPickerExtender2" runat="server" OnClientOpen="onClientOpen" OnColorPostBack="color_postback1" AutoPostBack="true" TargetProperty="style.backgroundColor"
    PopupButtonID="TextBox2" TargetControlID="TextBox2"></obout:ColorPickerExtender>

    protected void color_postback1(object sender, Obout.Ajax.UI.ColorPicker.ColorPostBackEventArgs e)
    { TextBox2.Style[HtmlTextWriterStyle.BackgroundColor] = e.Color;
    }

    See the attached image.

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #763037
    what is obout control it is not supporting in my system.showing error

  • #763038
    Hello Sadiq,

    In my one of response i have told you that you have to download the controls from link i have provided you.

    This is the download link : https://www.obout.com/inc/suite_download/default.aspx?type=20

    Hope you got it now.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments