Update panel RegisterClientScriptResource + AJAX

I have a problem that really makes me feel stupid. I have a custom control that inherits from a textbox. This textbox (at least for this example) just has a .js file embedded in a .dll.

In short, works great when there is no AJAX update in the panel. So I did some research and found that instead of using: Page.ClientScript.RegisterClientScriptResource, I have to use ScriptManger.RegisterClientScriptResource - I did it in the overrdive render method, but the javascript still doesn't fire.

Does anyone know what I am 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, for example: Attributes.Add ("onclick", "Test2 ();");

In Override Render:

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

      

However, I am still getting the "expected object" error.

I need a textbox to work with and without AJAX. I have imported System.Web.Extensions into my project to access the ScriptManger

Can someone please tell me what I am doing wrong? Again, this all worked fine without AJAX, I put the required stuff in AssemblyInfo.cs (WebResource: ,, etc.)

Thanks in advance: -)

--- UPDATE --- I brought back the control after trying it on the net without AJAX and I have the same problem. Not sure why I'm having a problem, I have another custom control in the same assembly that works really well - configure them exactly the same, only the difference is that one inherits WebControl, one that doesn't inherit TextBox ... in the one that works, I release html like Go and do this Where the one that is NOT working I Attributes.Add ("onclick", "CustomFunction ();");

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

Sorry for such a long post.

0


a source to share


1 answer


Try to pass this

instead this.Page

. ScriptManager only outputs scripts for controls that are being updated (UpdatePanel children that are).



I just noticed that you are doing this during Render. This is too late. Try PreRender instead.

+1


a source







All Articles