Sys.ScriptLoadFailedException when switching control visible property from false within partial page

A

Andrew Jocelyn

Hi

I have a web control which can be visible=false on page load. When I do a
postback with in an UpdatePanel (EnablePartialRendering=true) I get the
following error.

Microsoft JScript runtime error: Sys.ScriptLoadFailedException: The script
'DisplayLengthFunctions.js' failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script
error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

The control has a OnPreRender event as follows:

protected override void OnPreRender(EventArgs e)
{
ScriptManager.RegisterClientScriptInclude(
this,
this.GetType(),
"DisplayLengthFunctions",
ResolveClientUrl("~/DisplayLengthFunctions.js"));

ScriptManager.RegisterStartupScript(this, this.GetType(),
string.Format("{0}_DisplayLength", this.UniqueID),
string.Format("DisplayCounter('{0}','{1}_Counter',{2});", _textBox.ClientID,
this.UniqueID, this.MaxLength), true);
}

If I put the above in the OnLoad event I get the same error. If the control
is visible=true on on initial page load then postback works as expected.
What do I need to do to allow the control to work after a postback makes it
visible?

Thanks
Andrew
 
A

Allen Chen [MSFT]

Hi Andrew,

I think you can try the following code:

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
ScriptManager.RegisterClientScriptInclude(
this,
this.GetType(),
"DisplayLengthFunctions",
ResolveClientUrl("~/DisplayLengthFunctions.js"));

}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

ScriptManager.RegisterStartupScript(this, this.GetType(),
string.Format("{0}_DisplayLength", this.UniqueID),
string.Format("DisplayCounter('{0}','{1}_Counter',{2});",
_textBox.ClientID,
this.UniqueID, 2), true);
}

Please have a try and let me know if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Andrew Jocelyn

Hi Allen

Thanks for your quick response.

Your suggestion does work to a point. If I move the
ScriptManager.RegisterClientScriptInclude to the OnInit event and use the
control directly in a aspx page it works as expected.

If I create a new server control (inheriting CompositeControl) which uses
the first control and use this in the aspx page I get the same error as
before.

Microsoft JScript runtime error: Sys.ScriptLoadFailedException: The script
'DisplayLengthFunctions.js' failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script
error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

The only way I have found to make it work is to then add the same
ScriptManager.RegisterClientScriptInclude to the OnInit event of the new
control which is quite messy.

Any ideas?
Thanks
Andrew
 
A

Allen Chen [MSFT]

Hi Andrew,

Thanks for your update. Could you send me a demo that can reproduce this
problem? I'll debug it on my side to find a better solution. My email is
(e-mail address removed). Please update here after sending the project in case
I missed that email.

BTW, you can also try to set EnablePartialRendering="false" for the
ScriptManager. It's another way to eliminate this error.


Regards,
Allen Chen
Microsoft Online Support
 
A

Andrew Jocelyn

Hi Allen

I tried to recreate the problem this morning and it works fine now. I have
to assume that when I made changes to the code the compiler wasn't getting
the latest version for some reason.

Anyway, your suggestion appears to have solved my problem.

Thanks again
Andrew
 
A

Allen Chen [MSFT]

You're welcome Andrew. Have a nice day!

Regards,
Allen Chen
Microsoft Online Community Support

=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
=================================================
 
A

Andrew Jocelyn

Hi Allen

I'm still having problems with this issue. I thought it was fixed but it may
be that the error is obscured when the browser script debugging is disabled.

I've sent you a test project to your email address. To reproduce the error
please do the following:

1. In VS debug mode Open Default.aspx
2. Select the first item in the dropdown, and click insert

You should see the error:
Microsoft JScript runtime error: Sys.ScriptLoadFailedException: The script
'/WebSite1/WebResource.axd?d=VIVtZlXTi1Q0cYaUqsuMvtJoO2HZpcU39moCg2hcQqvr4xnysyy43dqxLPOLf7ZkgPswyYS0liAUbiQJJXjoCw2&t=633696911894505000'
failed to load. Check for:
Inaccessible path.
Script errors. (IE) Enable 'Display a notification about every script
error' under advanced settings.
Missing call to Sys.Application.notifyScriptLoaded().

3. Click 'Ignore' in the script debugger dialog.
4. the page then loads correctly, with the JS files. Typing in the textarea
box correctly fires the JS functions.

The problem is related to the OnInit event in the TextArea class in the Web
project.

protected override void OnInit(EventArgs e)
{
base.OnInit(e);

ScriptManager.RegisterClientScriptInclude(
this,
this.GetType(),
"DisplayLengthFunctions",
//ResolveClientUrl("~/DisplayLengthFunctions.js"));
this.Page.ClientScript.GetWebResourceUrl(this.GetType(),
"Empetus.SCS.Web.UI.WebControls.DisplayLengthFunctions.js"));
}

I hope you can reproduce the error and suggest a solution.
Thanks
Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top