It seems that AddThis only works when loading a window or document, and therefore a little trick is required here. Basically, the idea is that you should render the AddThis div in the first view, than capture it in the javascript field, and not show inside the div presented in the second view.
First of all, you need to change the server-side code, because you would like to include the whole file, not the script block. You should also do this only during the PageLoad method (I use C #, so you need to rewrite the call below).
ScriptManager.RegisterClientScriptInclude(this, GetType(), "Test", "http://s7.addthis.com/js/250/addthis_widget.js#username=xa-4d4c6a5604aba88b");
You can also just put it in your html header (like you) and get rid of the ScriptManager call, which is not needed in this case. Than you need to slightly change the contents of your multivisor
<asp:View ID="View1" runat="server"> <asp:Button ID="Button1" runat="server" Text="Button" /> <div style="left:-2000em; position:absolute;"> <div class="addthis_toolbox addthis_default_style addthis_32x32_style" id="addThis"> <a class="addthis_button_preferred_1"></a> <a class="addthis_button_preferred_2"></a> <a class="addthis_button_preferred_3"></a> <a class="addthis_button_preferred_4"></a> <a class="addthis_button_compact"></a> </div> </div> </asp:View> <asp:View ID="View2" runat="server"> <div id='addHere'></div> </asp:View>
For this, I wrote a simple javascript module that processes the task.
PageModules = {}; PageModules.AddThis = function () { var $addThis; function takeAddThis() { setTimeout(function () { $addThis = $('#addThis'); $addThis.remove(); }, 100); Sys.Application.remove_load(takeAddThis); } function fixAddThis() { var $addHere = $('#addHere'); if ($addHere.length) { $addHere.html($addThis); } } Sys.Application.add_load(fixAddThis); Sys.Application.add_load(takeAddThis); } ();
Note that PageModules only plays the role of a namespace to avoid messy work with the global scope. The AddThis module is self-initialized and is a kind of singleton. You will also need to reference jQuery or rework the body of internal methods. I wrapped your addThis div with an additional "hidden" div so as not to show it to the user. The add_load method is launched after loading all scripts and after creating all objects according to the msdn link
http://msdn.microsoft.com/en-us/library/bb383829.aspx
We need to takeAddThis to run only once to cancel this method after the first call. An additional timeout shifts our logic to the end of the queue, which ensures the correct implementation of this AddThis logic (I could also use $ (document) .ready from jQuery here, however I wanted to stay consistent.