I have a custom control, that is entirely dependent on jquery plugins. Everything is working fine as it is supposed to, but the problem arises when the control is set Visible = false or any of its parents is not Visible. Ideally, when an asp.net control is set Visible false, the engine doesnt render it, so my control is not being rendered on the page load. And when the control doesnt render, it does not load javascript resources, and hence jquery plugins dont bind when the control shows up on postback. This is a very basic problem, and as the developers, which are supposed to use it, they are just going to drag and drop the control on their pages, assuming it is working perfectly. I think there must be a work around for it. Pasted below is how I am loading resources.
ClientScriptManager cs = this.Page.ClientScript;
#region Loading JavaScript File(s)
string MenuPlugin = "MainMenuControl.Scripts.javascript_main.js";
cs.RegisterClientScriptResource(typeof(MainMenuControl.MenuControl), MenuPlugin);
string MenuInitializer = "MainMenuControl.Scripts.BuildMenu.js";
cs.RegisterClientScriptResource(typeof(MainMenuControl.MenuControl), MenuInitializer);
#endregion
#region Loading CSS File(s)
string cssUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "MainMenuControl.Styles.MenuStyle.css");
HtmlLink cssLink = new HtmlLink();
cssLink.Href = cssUrl;
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
this.Page.Header.Controls.Add(cssLink);
#endregion
#region Loading Image(s)
Page.ClientScript.GetWebResourceUrl(typeof(MainMenuControl.MenuControl), "MainMenuControl.Images.down.gif");
string script = string.Format(@"initializeMenu('{0}');", Page.ClientScript.GetWebResourceUrl(typeof(MainMenuControl.MenuControl), "MainMenuControl.Images.down.gif"));
Page.ClientScript.RegisterStartupScript(Page.GetType(), "InitImage", script, true);
#endregion
In the third last line of the code, I am calling a function with an image url that is loaded correctly. But for some reason, the javascript file(s) do(es)nt load and neither any browser show them in the loaded resources list.
Is there any solution to the problem, or is there anything that I am doing wrong? I am really helpless about this problem now and would appreciate any help.