ASP.NET WebForm with C#, Page_Load show colorpicker's color failed

2 posts, 0 answers
  1. 章民
    章民 avatar
    20 posts
    Member since:
    Oct 2012

    Posted 29 May 2017 Link to this post

    I want to set the color of color picker when the Page Load. But it always cannot find the rad color picker control. It always get null.

    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack == false)
        {               
            string szJS = "OptionSettingsLoad();";
            RadScriptManager.RegisterStartupScript(this, this.GetType(), "OptionSettingsLoad", szJS, true);
        }
    }

     

    The javascript has add the global function for initialize the TelerikDemo object and its function for color change.

    I cannot find the color picker control by

    var colorPickerDischargeTitleColor = $find("RadColorPickerDischargeTitleColor");

    the color Picker"colorPickerDischargeTitleColor " always be null.

     

    function (global, undefined) {
     
        var TelerikDemo = global.TelerikDemo = {};
     
        function OnClientColorChangeDischargeTitleColor(sender, eventArgs) {
     
            var colorPicker = $find("RadColorPickerDischargeTitleColor");
            var strColor = sender.get_selectedColor();
        }
     
        TelerikDemo.OnClientColorChangeDischargeTitleColor = OnClientColorChangeDischargeTitleColor;
     
        function OnClientColorChangeDischargeContentColor(sender, eventArgs) {
     
            //alert("Selected color is changed from " + eventArgs.get_oldColor() + " to " + sender.get_selectedColor() + ".");
            var colorPicker = $find("RadColorPickerDischargeContentColor");
            var strColor = sender.get_selectedColor();
        }
     
        TelerikDemo.OnClientColorChangeDischargeContentColor = OnClientColorChangeDischargeContentColor;
     
     
    })(window);
     
     
    function OptionSettingsLoad()
    {
        var LS_titleColor = localStorage.getItem(DISCHARGE_TITLE_COLOR);
        var LS_contentColor = localStorage.getItem(DISCHARGE_CONTENT_COLOR);
     
        var colorPickerDischargeTitleColor = $find("RadColorPickerDischargeTitleColor");
        var colorPickerDischageContentColor = $find("RadColorPickerDischargeConetnteColor");
     
        //alert("LS_titleColor=" + LS_titleColor);
       
        HiddenDischargeTitleColor.value = LS_titleColor;
     
        if (colorPickerDischargeTitleColor != null && LS_titleColor != null)
        {      
            colorPickerDischargeTitleColor.set_selectedColor(LS_titleColor);
        }
     
        HiddenDischargeContentColor.value = LS_contentColor;
     
        if (colorPickerDischageContentColor != null && LS_contentColor != null)
        {
            colorPickerDischageContentColor.set_selectedColor(LS_contentColor);
        }
    }

     

    My RadColorPciker control in aspx as below:

    <telerik:RadColorPicker ID="RadColorPickerDischargeTitleColor" runat="server" PaletteModes="HSB" ShowIcon="true" OnClientColorChange="TelerikDemo.OnClientColorChangeDischargeTitleColor" ></telerik:RadColorPicker>
     
    <telerik:RadColorPicker ID="RadColorPickerDischargeContentColor" runat="server" PaletteModes="HSB" ShowIcon="true" OnClientColorChange="TelerikDemo.OnClientColorChangeDischargeContentColor" ></telerik:RadColorPicker>

     

    Do I lose something to define or how to solve this problem?

  2. 章民
    章民 avatar
    20 posts
    Member since:
    Oct 2012

    Posted 01 Aug 2017 in reply to 章民 Link to this post

    I had solved this problem by add OnClientLoad to color picker control. And add some code in javascript to get the Color Picker control form OnClientLoad's sender and set a color.

    reference:
    http://demos.telerik.com/aspnet-ajax/colorpicker/examples/clientsideapi/defaultcs.aspx

Back to Top