Innovative Perspective

Javascript Files can’t be registered when using RegisterClientScriptResource in Custom Controls

Posted in .Net, AJAX, ASP.NET, Javascript, Tips, Web by mohammednour on February 4, 2010

I was trying to embed javascript file in a custom web control. I add the following line code in RenderControls method of the control.

Page.ClientScript.RegisterClientScriptResource(typeof(SampleCalendar), "TestWeb.Files.test.js");

When I tested a page containing the control, I realized the script is not registered. After investigation, I have found that I need to add this line of code in PreRender event of the control not in the RenderControls method (which make sense!)

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.