SIGN UP MEMBER LOGIN:    
ARTICLE

ColorPickerExtender Control in AJAX

Posted by Davin Martyn Articles | AJAX in C# November 26, 2011
ColorPicker extender is multi-browser compatible: it works with IE 6/7/8, Firefox, Safari and Goggle Chrome. ColorPicker is built on top of ASP.NET AJAX Control Toolkit and internally utilizes a Popup extender. ColorPicker is compatible with the UpdatePanel: can be placed inside the UpdatePanel.
Reader Level:

Introduction : ColorPicker is an ASP.NET AJAX extender that can be attached to any ASP.NET TextBox control. It provides client-side color-picking functionality with UI in a popup control.We can interact with the ColorPicker by clicking on a colored area to set a color. It requires a binary reference to the ASP.NET AJAX Control Toolkit. ColorPicker extender is multi-browser compatible: it works with IE 6/7/8, Firefox, Safari and Goggle Chrome. ColorPicker is built on top of ASP.NET AJAX Control Toolkit and internally utilizes a Popup extender. ColorPicker is compatible with the UpdatePanel: can be placed inside the UpdatePanel.

ColorPicker Property :

  • TargetControlID.
  • PopupButtonID.
  • PopupPositionID.

Step 1 : Open Visual Studio 2010.

  • Go to File-> New>WebSite.
  • Select ASP.NET WebSite.
COB1.gif

Step 2 : Go to Solution Explorer and right-click.

  • Go to Add->New Item.
  • Select Web From.
  • Default.aspx page open.
COB2.gif

Step 3 : Drag and drop AJAX Control from Toolbox.

  • Select ColorPicker Control, Label,TextBox.

Step 4 : Now go to the Default.aspx page write a simple code for application.

Code :

<
html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title
>
</head>
<
body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <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 />
        Fore ground color
        <asp:TextBox
            ID="txtCardColor"
            AutoCompleteType="None"
            Runat="server" />
        <asp:Button
            ID="btnPickColor"
            Text="Pick Color"
            Runat="server" />
        <asp:Label
            ID="lblSample"
            Runat="Server"> Sample </asp:Label>       
        <asp:ColorPickerExtender
            ID="txtCardColor_ColorPickerExtender" 
            TargetControlID="txtCardColor"
            PopupButtonID="btnPickColor"
            PopupPosition="TopRight"
            SampleControlID="lblSample"           
            Enabled="True"
            runat="server">
        </asp:ColorPickerExtender>
        <br />
        <br />
        Back ground color
        <asp:TextBox
            ID="txtCardColor0"
            AutoCompleteType="None"
            Runat="server" />
        &nbsp;<asp:Button
            ID="btnPickColor0"
            Text="Pick Color"
            Runat="server" onclick="btnPickColor0_Click" />
            <asp:Label
            ID="lblSample0"
            Runat="Server"> Sample1</asp:Label>
            <asp:ColorPickerExtender ID="ColorPickerExtender1" TargetControlID = "txtCardcolor0"  PopupButtonID="btnPickColor"
            PopupPosition="TopRight"
            SampleControlID="lblSample0"           
            Enabled="True"  runat="server">
        </asp:ColorPickerExtender
           
        <br />
        <br />
       
        <asp:Button
            ID="btnSubmit"
            Text="Submit"
            Runat="server" OnClick="btnSubmit_Click" />
       
<br />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"
            style="z-index: 1; left: 10px; top: 361px; position: absolute; height: 133px; width: 275px; text-align: center; font-family: 'Times New
Roman', Times, serif;
font-size: xx-large"></asp:Label>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:Panel ID="pnlResults" Visible="false" runat="server">
            <h2>Your Selection</h2>
            Selected Card Text:
            <asp:Label
                ID="lblSelectedText"
                Runat="server" />
            <br />       
            Selected Card Color:
            <asp:Label
                ID="lblSelectedColor"
                Runat="server" />
        </asp:Panel>
    </div>
    </form
>
</body>
</
html>

Step 5 : Now go to Design option on Default.aspx page and double-click in submit Button and write a code.

Code :

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // Show the panel
        pnlResults.Visible = true;
        // Show the selected values
        lblSelectedText.Text = txtCardText.Text;            
        lblSelectedColor.Text = txtCardColor0.Text;
        Label1.Text = txtCardText.Text;
        //Int32 x = Convert.ToInt32();
        Label1.ForeColor = System.Drawing.ColorTranslator.FromHtml("#"+ txtCardColor.Text);
        Label1.BackColor = System.Drawing.ColorTranslator.FromHtml("#" + txtCardColor0.Text);
    }

Step 6 : Now add the ScriptManager for the run in AJAX application.

Step 7 : Now go Default.aspx.cs option and see the simple page_load event option and define the namespace.

Step 8 : Now Press F5 and run the applicaiton.

COB8.gif

Step 9 : Define the value of card text and click in picker color and select the color.

COB9.gif

Step 10 : Now we click in Submit Button and find the output.

COM10.gif


Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor