Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Script problem when loading dynamic property

Vote:
 

Hi,

I have a custom property where in I call a jquery plugin with the below code.

Code:

Page.ClientScript.RegisterStartupScript(GetType(), "dropdownchecklist-setup" + this.GetHashCode(), string.Format("$('#{0}').custSelectBox();", listBox.ClientID), true);

This works perfectly when the property is added to any pagetype. But this fails when the property is added as a dynamic property. It fails giving the below error.

$('#ctl00_FullRegion_MainRegion_EditForm_PredefinedLocations_DropdownCheckList').custSelectBox() is not a function.

I have checked that all the required files are being loaded. What might be the problem ? Why is it failing only when called from dynamic properties? SHould I be doing any thing different when loading from dynamic properties?.

Please suggest

#44118
Oct 01, 2010 11:58
Vote:
 

Are u really really sure that jquery is loaded? If it is, have you tried $(document).ready(function() { $('#{0}').custSelectBox(); });"?

#44141
Oct 01, 2010 15:12
Vote:
 

I am calling th ebelow method at the end in CreateEditControls(). As I told it works fine as a page property. Problem is only when it is set as dynamic property.

private void RegisterResources()
        {
           
            if (!Page.ClientScript.IsClientScriptIncludeRegistered("jQuery"))
            {
                Page.ClientScript.RegisterClientScriptInclude("jQuery", "/CustomProperties/Scripts/jquery-min.js");
            }

            if (!Page.ClientScript.IsClientScriptIncludeRegistered("dropdownchecklist"))
            {
                Page.ClientScript.RegisterClientScriptInclude("dropdownchecklist", "/CustomProperties/Scripts/cust_select_plugin.js");
            }

   
           Page.ClientScript.RegisterStartupScript(GetType(), "dropdownchecklist-setup" + this.GetHashCode(), string.Format("$('#{0}').custSelectBox();", listBox.ClientID), true);
        }

 

If I change "$('#{0}').custSelectBox();" the to "$(document).ready(function() { $('#{0}').custSelectBox(); });" it gives me invalid string error durin runtime.

#44145
Oct 01, 2010 16:04
Vote:
 

You need double {{ }} to wrap the method when doing string.format. $(document).ready(function() {{ .... }});

#44149
Oct 01, 2010 18:03
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.