Saturday, March 10, 2012

use of text/xml-script not working

xml-script has been moved to Preview component. You have to add reference to Microsoft.Web.Preview.dll and add scriptmanager as followed:

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Assembly="Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Name="Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Name="Microsoft.Web.Resources.ScriptLibrary.PreviewGlitz.js" />
<asp:ScriptReference Assembly="Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Name="Microsoft.Web.Resources.ScriptLibrary.PreviewDragDrop.js" />
</Scripts>
</asp:ScriptManager>


hello.
well, if you only want to use xml-script with the traditional components, you only need the 1st include (use the later?if?you?want?to?get?support?for?animations?and?drag-n-drop).
Many thanks to both of you, alexmajin and Luis Abreu.

Hi,

I used to also use text/xml-script in Atlas for calling a javascript function (that contains calling a webservice) after the js proxy is created:

<scripttype="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<references>
</references>
<components>
<application id="application" load="OnApplicationLoad" />
</components>
</page>
</script>

This no longer works in Beta 2. What's an alternative way to do this besides using setTimeout to wait some arbitrary number of seconds before calling that javascript function "OnApplicationLoad"?


hello.

the code you've shown should be working. i think that the only difference is that now you can't insert the proxy by adding an element to the reference section of xml-script.


Hi, thanks for the reply! Yeah I don't know what to say.

So this works:

<scripttype="text/javascript">

window.onload = OnApplicationLoad;

</script>then as soon as I changed it to:

<scripttype="text/xml-script">

<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">

<components>

<application id="application" load="OnApplicationLoad" />

</components>

</page>

</script>

it doesn't load anymore...

I am hesitant to use window.onload because it didn't always work, proxy or other Atlas related files didn't finish downloading and I get "[webservice namespace name] is not defined" javascript errors.


Jahn -- your xml should work. But it could be that the preview script, which processes the xml script, is not loading. Did you add the reference as Luis described? If you did, it may still be failing to load for other reasons. Do a view source on your page, and find references to ScriptResource.axd. Request them directly by copy/pasting the url into the browser. Do this for each ScriptResource.axd url you see. The goal is to make sure each script can be loaded correctly.

Alternatively, download a very useful http debugging tool called Fiddler. With it you can monitor all requests made from the browser, see the responses, etc. So using Fiddler you'd be able to see all the requests to ScriptResource.axd at once.


I should also point out that it may simpler for you to just use the so called "magic" function: pageLoad. If you define a function with that name it will be called on application load automatically, err, automagically.

function pageLoad() {
// do stuff
}


I've found you can also add an "onload" handler in the following 2 ways:

function main()
{
// Do stuff
}

..

// then either
<script>
Sys.Application.add_load(main);
</script
or

<script>
Sys.Application.get_events().addHandler("load", main);
</script>


Hi,

just some clarifications:

1. Programmatically handle the Application's load event:

Sys.Application.add_load(onPageLoad);function onPageLoad(sender, e) {// Handle load event.}
2. Alternative to 1 (as InfinitiesLoop suggested): 
function pageLoad(sender, e) {// Handle load event.}
3. Handle the Application's load event with xml-script (Futures December CTP): 
<%@. Page %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Hello XML-script</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="TheScriptManager" runat="server"> <Scripts> <asp:ScriptReference Assembly="Microsoft.Web.Preview" Name="PreviewScript.js" /> </Scripts> </asp:ScriptManager> <script type="text/xml-script"> <page xmlns="http://schemas.microsoft.com/xml-script/2005"> <components> <application load="page_load" /> </components> </page> </script> <script type="text/javascript"><!-- function page_load(sender, e) { alert("Hello Xml-script!"); } //--> </script> </form></body></html>

@.Garbin, I'm still inclear as to exactly why window.onload is no good (but I KNOW that it isn't!).

Is it because the script manager is loading script async after the page has loaded?


Hi,

window.onload is used to startup the Microsoft Ajax runtime. If you have any application code that uses the MS Ajax library, then it's safe to handle the load event raised by Sys.Application, because it's raised when the startup is complete, all the external js files have been loaded and all the client components have been created and initialized.


Thanks, everyone.

First, I still don't understand the reference section of the text/xml-script. That's why I removed the element after reading Luis's post, since it was empty anyway. Just now, I also checked running the only/ScriptResource.axd?d=p5m4Esz... in the browser, it loaded fine. This is Beta 2 version, by the way, tomorrow I will try to upgrade to RC.

But I have another project in question. I upgraded from Beta 1 to RC today. I used to use

Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(OnApplicationLoad);

that worked perfectly fine. After the upgrade, it gave javascript error that "Sys.WebForms has no properties". I looked up the documentation, looks like Sys.WebForms is for UpdatePanel? My page has no update panel, just a webservice. I don't know why it worked before and stopped working now...

So after reading all your posts, I changed it to

Sys.Application.add_load(OnApplicationLoad);

and that worked!

function pageLoad(sender, e) {
OnApplicationLoad();
}

also worked. However,

<scripttype="text/xml-script">
<page xmlns="http://schemas.microsoft.com/xml-script/2005">
<components>
<application load="OnApplicationLoad" />
</components>
</page>
</script>

did not work for me. I must be missing something. Probably the same reason that I don't understand what reference does.

Seems like there are many ways to do the same thing. I don't know if I should be glad or confused.

Thanks, again!


I tried doing what you showed but I keep getting the following error:

Assembly 'Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not contain a Web resource with name 'Microsoft.Web.Resources.ScriptLibrary.PreviewScript.js'.

I have installed the January CTP. What am I doing wrong?

David

No comments:

Post a Comment