Debbie Wright
Top achievements
Rank 1
Debbie Wright
asked on 11 Mar 2008, 03:04 PM
I have a form inside a RadAjaxUpdatePanel, the form uses a custom buttom to preview data from the form. It does this using a javascript onclick event that is defined in a .js class in the custom project ( seperate from the form). the .js file is registered like so:
The page shows that the script is registered (using IsClientScriptIncludeRegistered), However when I try to use the button, I get a javascript error "object expected".
I know the javascript code works, It only broke when I tried to ajax the page. does anyone know what I can do to fix this?
| ClientScriptManager cs = this.Page.ClientScript; |
| Type rsType = this.GetType(); |
| cs.RegisterClientScriptInclude("JobScript", cs.GetWebResourceUrl(rsType, "CareerCenter_Classes.JsScripts.Jobs.js")); |
The page shows that the script is registered (using IsClientScriptIncludeRegistered), However when I try to use the button, I get a javascript error "object expected".
I know the javascript code works, It only broke when I tried to ajax the page. does anyone know what I can do to fix this?
11 Answers, 1 is accepted
0
Hi Debbie,
Page.ClientScript .. approach is no longer working in MS AJAX as the page parser is bundled with the ScriptManager. You can use the static methods of the ScriptManager instead:
ScriptManager.RegisterClientScriptInclude(...)
Hope this helps.
Best wishes,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Page.ClientScript .. approach is no longer working in MS AJAX as the page parser is bundled with the ScriptManager. You can use the static methods of the ScriptManager instead:
ScriptManager.RegisterClientScriptInclude(...)
Hope this helps.
Best wishes,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Debbie Wright
Top achievements
Rank 1
answered on 11 Mar 2008, 03:28 PM
Thanks Steve,
do you know how to convert the code? or can you point me to a good site to use?
Thank you
do you know how to convert the code? or can you point me to a good site to use?
Thank you
0
Hello Debbie,
Your code should be something like this:
ScriptManager.RegisterClientScriptInclude(this.Page, this.GetType(), "JobScript", cs.GetWebResourceUrl(rsType, "CareerCenter_Classes.JsScripts.Jobs.js"));
You can see the class reference from the MS AJAX documentation directly here.
All the best,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Your code should be something like this:
ScriptManager.RegisterClientScriptInclude(this.Page, this.GetType(), "JobScript", cs.GetWebResourceUrl(rsType, "CareerCenter_Classes.JsScripts.Jobs.js"));
You can see the class reference from the MS AJAX documentation directly here.
All the best,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Debbie Wright
Top achievements
Rank 1
answered on 12 Mar 2008, 01:08 PM
I made the changes you suggested, and I am still getting the javascript error.
should I be using one of the other ScriptManager methods?
0
Hi Debbie,
Did you kept the ClientScriptManager cs = this.Page.ClientScript; line just before the converted one? Try debugging further by setting debugger; in the .js file you are trying to load and step through with F10 to see which line is throwing the error.
All the best,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Did you kept the ClientScriptManager cs = this.Page.ClientScript; line just before the converted one? Try debugging further by setting debugger; in the .js file you are trying to load and step through with F10 to see which line is throwing the error.
All the best,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Debbie Wright
Top achievements
Rank 1
answered on 12 Mar 2008, 02:53 PM
Yes I did.
the error isn't getting thrown in the .js file, it's getting thrown by the button "Object expected"
the error isn't getting thrown in the .js file, it's getting thrown by the button "Object expected"
OnClientClick="return btnPreview_OnClick();">
I think this means that It still can't find the .js file, even though it is registered.
0
Hello Debbie,
You should return false after the invoked function in order to prevent the default submit behavior of the button. Try this instead:
OnClientClick="if (!btnPreview_OnClick()); return false;"
Sincerely yours,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
You should return false after the invoked function in order to prevent the default submit behavior of the button. Try this instead:
OnClientClick="if (!btnPreview_OnClick()); return false;"
Sincerely yours,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Debbie Wright
Top achievements
Rank 1
answered on 18 Mar 2008, 07:34 PM
That doesn't help, still getting the same javascript error
0
Hi Debbie,
Unfortunately I have no other suggestions as to what else can be causing the error. The best way to help you further, would be if you open a support ticket and attach a runnable page showing the problem at hand. After we review it, we would be able to advise you accordingly.
Sincerely yours,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Unfortunately I have no other suggestions as to what else can be causing the error. The best way to help you further, would be if you open a support ticket and attach a runnable page showing the problem at hand. After we review it, we would be able to advise you accordingly.
Sincerely yours,
Steve
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Ryan
Top achievements
Rank 1
answered on 20 May 2011, 10:03 PM
I've been searching for information on the forums, and this is the closest post I could find related to my issue with javascript files loading in custom widgets. I can register the script, but the javascript doesn't actually work until a page refresh or preview. This error only occurs in edit mode of the custom widget view, not the designer. Are the scripts in the scriptmanager cached, and not affected until a refresh? The desired behavior is to be able to drag a widget on to the page, have the javascript file load into the script manager, and be available for callbacks immediately, rather than on a refresh.
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName = "xx.Widgets.xx.Resources.xx.xx.js";
ClientScriptManager cs = this.Page.ClientScript;
//cs.RegisterClientScriptResource(typeof(xx.Widgets.xx), resourceName);
ScriptManager.RegisterClientScriptInclude(this.Page, this.GetType(), "Widgets", cs.GetWebResourceUrl(this.GetType(), resourceName));
}
{
base.OnPreRender(e);
string resourceName = "xx.Widgets.xx.Resources.xx.xx.js";
ClientScriptManager cs = this.Page.ClientScript;
//cs.RegisterClientScriptResource(typeof(xx.Widgets.xx), resourceName);
ScriptManager.RegisterClientScriptInclude(this.Page, this.GetType(), "Widgets", cs.GetWebResourceUrl(this.GetType(), resourceName));
}
0
Hi Ryan,
Sitefinity uses output caching which enabled by default. The cache for a page is invalidate when it expires (2 minutes sliding expiration), edit and publish the page, you compile your web application project, restart your website or recycle the application pool.
Kind regards,
Radoslav Georgiev
the Telerik team
Sitefinity uses output caching which enabled by default. The cache for a page is invalidate when it expires (2 minutes sliding expiration), edit and publish the page, you compile your web application project, restart your website or recycle the application pool.
Kind regards,
Radoslav Georgiev
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items