views:

393

answers:

1

Hello,

I have a problem that is really making me feel dumb. I have a custom control that inherits textbox. This textbox (at least for this example) simply has a .js file that is embedded in the .dll.

Long story short, works great when not in an AJAX update panel. So i did some research and found that instead of using: Page.ClientScript.RegisterClientScriptResource, i should use ScriptManger.RegisterClientScriptResource - i have done this in the overrdive render method, but the javascript still does not fire.

Anyone know what im doing wrong?

example: i have a folder in my project called Scripts - it contains myscript.js My Assembly is called Jim.Bob.Controls

I add attributes to my controls ie: Attributes.Add("onclick", "Test2();");

In the Override Render:

ScriptManager.RegisterClientScriptResource(this.Page, typeof(CustomTextBox), "Jim.Bob.Controls.Scripts.myscript.js");

Yet i still get 'object expected' error.

I need my textbox to work with and w/o AJAX. I imported System.Web.Extensions into my project to access ScriptManger

Can someone please tell me what im doing wrong? Again, this whole thing worked fine w/o AJAX, i have put the necessary stuff into the AssemblyInfo.cs (WebResource:,,,,etc)

Thanks in advance :-)

--- UPDATE --- I reverted the control, trying it in a non AJAX web and i am having the same problem. Not sure why i have a problem, i have another custom control in the same assembly that is working just fine - have them setup the exact same way, only difference is the one that is working inherits WebControl, the one that is not inherits TextBox ... in the one that is working i emmit html like Go and do it Where the one that is NOT working i have Attributes.Add("onclick", "CustomFunction();");

Also, if i do Attributes.Add("onclick", "alert('hello');"); it works fine.

Sorry for such a long post.

A: 

Try to pass this instead of this.Page. The ScriptManager would output scripts only for controls which are being updated (children of UpdatePanel that is).

I've just noticed that you are doing this during Render. That's too late. Try PreRender instead.

korchev
I have tried that also, same results. Thank you for the reply :-)
schmoopy