November 07, 2006 - Posts

xml-script in beta 2
Tue, Nov 7 2006 17:25
well, after writing about it in several posts, I think

that all the issues I've mentioned are solve now. btw, you should know that if you don't define a global xml namespace, the AJAX extensions predefined namespace will be used by default.

by luisabreu | with no comments
Filed under: ,
Localizing scripts
Tue, Nov 7 2006 17:18

Well, what about this one? Beta 2 offers support for automatic loading of localized scripts (I hope i got the word right). So, why is this good? Here's a quick example: suppose you need to show messages to the user in the client side and you also need to support users that speak two different languages. How will you do that? maybe by inserting a global variable from an ASP.NET page which tells you the current locale so that you can show the correct error message? Well, guess what (oki, you've already guessed it by know, right?): you can do this easily. The idea is simple; you define your main library file and then several resource javascript files which contain specific locale values for global variables which you're using from your library. So, let's start by creating the "main" library (a simple js file will do it):

//localizado.js
alert( info );
if( Sys && Sys.Application ){
      Sys.Application.notifyScriptLoaded();
}

Nothing new here... the only thing to remember is that info will be inserted by one of the resource files. When you build resource files you must use a predefined name convention: you should call your files library_filename.culture.js. To illustrate what  I mean, i'll create 2 resource files: one in pt and another one in en:

// localizado.pt-PT.js
var info = "Ola"
if( Sys && Sys.Application ){
    Sys.Application.notifyScriptLoaded();
}

// localizado.en-UK.js
var info = "hello"
if( Sys && Sys.Application ){
     Sys.Application.notifyScriptLoaded();
}

The platform can load the correct file for you: you just need to set the EnableScriptLocalization property to true and add the necessary entries to the ResourceUICultures of the ScriptReference element. Btw, don't forget to configure the ASP.NET page to use the correct culture (in this case, I'm using the Auto option so that the current UI culture depends on the language defined on the browser):

<%@ Page Language="C#" Culture="Auto" UICulture="en-UK" %>
<!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>Untitled Page</title>
   </head>
<body>
<form id="form1" runat="server">
<asp:Scriptmanager runat="server" id="manager" EnableScriptLocalization="true">
  <Scripts>
      <asp:ScriptReference Path="localizado.js"
          ScriptMode="release" ResourceUICultures="en-US, pt-PT" />
     <asp:ScriptReference Path="localizado.js" 
           ScriptMode="release" />
  </Scripts>
</asp:Scriptmanager>
</form>
</body>
</html>

And that's all for today.

by luisabreu | 1 comment(s)
Filed under: ,
Loading external scripts
Tue, Nov 7 2006 16:51

During beta 1, we could easily load external scripts by adding a <script> element to the page, by using the ClientScriptManager and even by using the ScriptReference element in order to add references to external Javascript files. Beta 2 introduces some changes when you load a script file through a ScriptElement entry. The docs mention this briefly by saying the following:

"Component developers and page developers creating file-based script libraries that are registered
with the ScriptManager control should include a JavaScript code snippet that indicates that the
library has been downloaded by the client. Although this is not required in all browsers,
Safari requires this to be able to dynamically load scripts."

 

After talking with my good friend Garbin (thanks for pointing me in the right direction) and after running some tests, I'd say that this means is that now we must call the notifyScriptLoaded method exposed by the global Sys.Application object. To test this, let's build a simple page. We'll start by defining a Javascript file (test.js):

alert("howdy! I'm an external file" );
if( Sys && Sys.Application ){
   Sys.Application.notifyScriptloaded();
}

Now, you must have noted the test for Sys and Sys.Application. Well, i've put it there since i'm lazy and I'd like to use my libraries in several web apps (which means that it has to run when i have a global Sys.Application object - which allways happens in an AJAX page - and when i don't). btw, i could have gone further and added a test for the method but, as I said, I'm lazy :)

Now, adding the file is really simple, like the following page shows:

<%@ Page Language="C#" %>
<!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>Untitled Page</title>
     </head>
<body>
  <form id="form1" runat="server">
      <asp:ScriptManager runat="server" ID="manager">
        <Scripts>
               <asp:ScriptReference Path="test.js" />
        </Scripts>
     </asp:ScriptManager>
   </form>
</body>
</html>

Nothing to difficult, but still something that must be registered for future use.

by luisabreu | 17 comment(s)
Filed under: ,
Setting the focus on a control after an async postback
Tue, Nov 7 2006 16:28

I already had a post prepared on how to set the focus on a control after an async postback. Unfortunately, it went directly to "garbadge" since now it's all too easy: we can do that by using the new SetFocusmethod exposed by the ScriptManager class. Here's a demo page that does just that!

 

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
  void h(object sender, EventArgs e)
  {
       manager.SetFocus(info);
   }
 </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
     <title>Untitled Page</title>
    </head>
<body>
 <form id="form1" runat="server">
    <asP:Scriptmanager runat="server" id="manager" />
    <asp:UpdatePanel runat="server" ID="panel">
       <ContentTemplate>
            <asp:TextBox runat="server" ID="info" />
            <asp:Button runat="server" ID="bt" Text="focus" OnClick="h" />
       </ContentTemplate>
     </asp:UpdatePanel>
 </form>
</body>
</html>

by luisabreu | 8 comment(s)
Filed under: ,
.NET 3.0 final version has been released!
Tue, Nov 7 2006 6:45

I've just read it in JPC's blog (which is in Pt) that it's out!

by luisabreu | with no comments
Filed under:
Ajax extensions: beta 2 is out!
Tue, Nov 7 2006 3:34

Yes, the november release is out and you can get it from this page.

by luisabreu | with no comments
Filed under: ,