This is a migrated thread and some comments may be shown as answers.
ASP.NET WebForm with C#, Page_Load show colorpicker's color failed
1 Answer 15 Views
This is a migrated thread and some comments may be shown as answers.
章民
Top achievements
Rank 1
章民 asked on 29 May 2017, 05:54 AM

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?

1 Answer, 1 is accepted

Sort by
0
章民
Top achievements
Rank 1
answered on 02 Aug 2017, 03:43 AM

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

Asked by
章民
Top achievements
Rank 1
Answers by
章民
Top achievements
Rank 1
Share this question
or