<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Atlas 6: When 'this' is not really 'this'</title><link>http://msmvps.com/blogs/omar/archive/2006/09/23/Atlas-6_3A00_-When-_2700_this_2700_-is-not-really-_2700_this_2700_.aspx</link><description>Atlas callbacks are not executed on the same context where they are called. For ex, if you are making a Page method call from a javascript class like this: function SampleClass() { this .id = 1 ; this .call = function () { PageMethods.DoSomething( &amp;quot;</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: Atlas 6: When 'this' is not really 'this'</title><link>http://msmvps.com/blogs/omar/archive/2006/09/23/Atlas-6_3A00_-When-_2700_this_2700_-is-not-really-_2700_this_2700_.aspx#341418</link><pubDate>Sun, 26 Nov 2006 02:37:02 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:341418</guid><dc:creator>Tim Scarfe</dc:creator><description>&lt;p&gt;Shame I missed this one at the time.. :)&lt;/p&gt;
&lt;p&gt;This problem always was a classic in javascript i.e. closures get executed in global scope - but the workaround is this:&lt;/p&gt;
&lt;p&gt;function SampleClass()&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;this.id = 1;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;this.call = function()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt;	var obj = this;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PageMethods.DoSomething( &amp;quot;Hi&amp;quot;, function(result)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;debug.dump( obj.id );&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} );&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;I feel like it's 1999 again ;)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=341418" width="1" height="1"&gt;</description></item><item><title>re: Atlas 6: When 'this' is not really 'this'</title><link>http://msmvps.com/blogs/omar/archive/2006/09/23/Atlas-6_3A00_-When-_2700_this_2700_-is-not-really-_2700_this_2700_.aspx#241245</link><pubDate>Fri, 03 Nov 2006 06:42:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:241245</guid><dc:creator>Murali</dc:creator><description>Hi

I have a weird problem with Pagemethods as well:

1. I use "PageMethods" to call the function on the ASPX Page. This method is a static method and it is **NOT IN** my code behind file. It is decorated by "webmethod" and "scriptmethod" attributes as required by Ajax Extensions Beta 1. I use javascript to invoke the "PageMethods.&lt;functionname&gt;" on click of a button.

2. The called method returns a message from resource file at the folder App_GlobalResources. I have 2 variations of the resource file (ta-IN and the base en-US)

3. The page culture is set to "auto" and uiculture also "auto"

4. In my internet explorer , languages section I have kept "ta-IN" as first preference and "en-US" as second.

5. When the page is loaded all the controls are localized correctly to "ta-IN". But atlas callbacks using "PageMethods.&lt;FunctionName&gt;" do not recognize the culture and always return the string from "en-US" files.

6. I debugged a call back to find System.Threading.Thread.CurrentCulture and System.Threading.Thread.CurrentUICulture as "en-US" during callbacks whereas other page processing events such as PageLoad , prerender it is correctly set to "ta-IN".

So the question is how do I get my callbacks to return correct strings in sync with the page localization. Thanks for your time and effort.

&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=241245" width="1" height="1"&gt;</description></item><item><title>re: Atlas 6: When 'this' is not really 'this'</title><link>http://msmvps.com/blogs/omar/archive/2006/09/23/Atlas-6_3A00_-When-_2700_this_2700_-is-not-really-_2700_this_2700_.aspx#183723</link><pubDate>Wed, 18 Oct 2006 06:07:04 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:183723</guid><dc:creator>Dav Evans</dc:creator><description>Hi Omar.
I am having the problem you described above where Atlas is returning after a webservice call into a different context, and so "this" no longer refers to the javascript class that made the original call. Unfortunately your solution of using the following client-side code:

function SampleClass() { 
      this.id = 1; 
      this.call = function() {             PageMethods.DoSomething( "Hi", Function.createDelegate( this, function(result) { debug.dump( this.id ); } ) ); } }

isnt working for me. when I execute the call method, I get back null rather than "1" (the id specified in the class).

Any ideas how I might get the callback to be in the context of my class so that I can refer to other members of the class?

Thanks&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=183723" width="1" height="1"&gt;</description></item></channel></rss>