How do I create a feature where users can design card to their taste?

Donald Symmons 3,066 Reputation points
2023-05-23T01:07:22.8633333+00:00

Hello,

I have seen web applications where users are given the chance to design their cards themselves, choose colors and backgrounds. And I am trying to create a similar situation where a user can design and select background and font color for an invitational card. I thought of it and I don’t know any other way besides what I am about to explain here. I am using AjaxControlToolkit ColorPickerExtender to choose background color of card. There is a TextBox which contains color code when a color is selected from the AjaxControlToolkit ColorPickerExtender.  Now I was thinking if it is to save the color code in the database table and retrieve it on another page. For example, after user has selected the background color of the card using the AjaxControlToolkit ColorPickerExtender, and the user clicks the save button and the color code in the TextBox is saved in the database table. Then when user navigates to the page where he or she can print the card, the chosen background color of the card will be retrieved and displayed on the card background. Please I want to know if this is the right approach to this, and how can I really do what I explained above?

Thank you

<div class="card1" runat="server" id="bgCard" style="width: 100%; height: auto; border: 0.3px solid #c7c7c7; border-radius: 5px; position: relative;">
                                        <div class="card-body">
                                        </div>
                                    </div>


<div class="input-group" style="font-size: 4pt;">
                                        <asp:TextBox ID="TextBox1" runat="server" AutoCompleteType="None" Font-Size="4pt" CssClass="form-control" />
                                        <cc1:ColorPickerExtender ID="ColorPicker1" runat="server" TargetControlID="TextBox1"
                                            PopupButtonID="ColorBtn" PopupPosition="TopRight" OnClientColorSelectionChanged="LabelColor" />
                                        <div class="input-group-append">
                                            <span class="input-group-text" id="ColorBtn" runat="server" style="height: auto; background-color: transparent; color: #404344;">
                                                <span id="toggle_picker" class="fad fa-eye-dropper" aria-hidden="true" style="cursor: pointer; font-size: 10pt; border: none;"></span>
                                            </span>
                                        </div>
                                    </div>
<script type="text/javascript">
        function LabelColor(sender) {
           // document.getElementById("bgCard").style.color = "#" + sender.get_selectedColor();
            document.getElementById("bgCard").style.backgroundColor = "#" + sender.get_selectedColor();
        }
    </script>

When I save the color code that is displayed in the TextBox this is how it is in my table

Id BgColor email CardID
1 0b2436 ******@mail.com 20

 Then, this is how I am retrieving the background color from database 

string color = dr["BgColor"].ToString();//my color string bgCard.Style.Add("background-color", color);

So, in trying to retrieve the saved color from database table, I tried this but then I realized that color code come after a hashtag (#), for example: #0b2436, so I thought to myself how will only numbers represent color code without the hashtag?

So please I ask if anybody has a better idea on how I can achieve what I explained above?

Developer technologies | .NET | Other
Developer technologies | ASP.NET | Other
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. QiYou-MSFT 4,341 Reputation points Microsoft External Staff
    2023-05-23T08:25:47.56+00:00

    Hi @Donald Symmons

    It can be implemented, and for the convenience of the demonstration I use Session to pass the data.

    Step 1: Select the color the user wants and enter his email address

    <body>
        
        <form id="form1" runat="server" >
             <div >
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
            
            <h1>Create a Business Card</h1>
        
            <asp:Label 
                ID="lblCardText" 
                Text="Card Text"
                AssociatedControlID="txtCardText"
                runat="server" />
            <br />
            <asp:TextBox
                ID="txtCardText"
                Runat="server" />
                
            <br /><br />    
        
            <asp:Label 
                ID="lblCardColor" 
                Text="Card Color"
                AssociatedControlID="txtCardColor"
                runat="server" />
            <br />
            <asp:TextBox
                ID="txtCardColor"
                AutoCompleteType="None"
                Runat="server" />
            <asp:Button
                ID="btnPickColor"
                Text="Pick Color"
                Runat="server" />
            <asp:Label
                ID="lblSample"
                Runat="Server" BackColor="#33FF99"> Sample </asp:Label>        
            <cc1:ColorPickerExtender 
                ID="txtCardColor_ColorPickerExtender"  
                TargetControlID="txtCardColor"
                PopupButtonID="btnPickColor"
                PopupPosition="TopRight"
                SampleControlID="lblSample"            
                Enabled="True" 
                runat="server">
            </cc1:ColorPickerExtender>
                
            <br /><br />
            
            <asp:Button
                ID="btnSubmit"
                Text="Submit"
                Runat="server"
                onclick="btnSubmit_Click"/>
    
           
        
        </div>
        </form>
    </body>
    
    
    
    
     public string color="";
            protected void Page_Load(object sender, EventArgs e)
            {
    
                
             
            }
    
            protected void btnSubmit_Click(object sender, EventArgs e)
            {
                color = "background-color:#"+ txtCardColor.Text;
                Session["Color"] = color;
                Session["Email"] = txtCardText.Text;
                Response.Redirect("WebForm1.aspx");
            }
    

    Step 2: Receive the data of the previous page through the Session and transfer the value from the back-end to the front-end through the <%=%> method.

     public partial class WebForm1 : System.Web.UI.Page
        {
            public static string a;
            public static string b;
            protected void Page_Load(object sender, EventArgs e)
            {
                 a = Session["Email"].ToString();
                 b = Session["Color"].ToString();
    
            }
        }
    
    
    
    
    <form id="form1" runat="server">
           
           Email:<%=a %>
           Color:<%=b %>
            <div style=<%=b %>>
                <br />
                Test
            </div>
        </form>
    

    Similarly, if you are stored through a database, just store the data of page 1 in the database and read it out on page 2.

    Card

    Best Regards

    Qi You


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.