I am always wary about replying to 4 year old posts however since this is the only forum topic I came across when searching for a solution to exactly the same problem building with and running on DNN 4.9 where the issue still occurs (maybe it's fixed in DNN 5 or 6 I don't know)
... well here goes.
The DNN FormatEmail generates something like (since I am not copying code probably not going to be 100% accurate here)
<script> document.writeto String.fromCharCode('10','19', ..... etc .... '90'); </script>
Javascript (etc) from the initial post is not recalled when a postback returns when using partial rendering. Neither is directly written scripts returned in the postback response - presumably something to do with the various Script Manager onLoad etc calls not parsing the HTML for scripts.
To make a script run explicitly on a postback you need to invoke the RegisterStartupScript method of the ScriptManager.
DNN 4 AJAX framework doesn't explicitly expose this script manager method but it is very easy to create your own ... along the lines of the following in a global class (see MyAJAX.RegisterStartupScript method in the class at the bottom)
Now we take the FormatEmail response and strip it down to the String.fromCharCode( ....) bit and register a startup script setInnerHTML that puts the String.fromCharCode(...) part into the innerHTML of the (in my case Label) control (see MyAJAX.FixFormedStringCodeScript method in the class at the bottom)
The javascript is quite basic then and I've included it just above the MyAJAX class below
What happens now is that instead of actually writing to the document directly via a script, the ScriptManager inherently dumps a pile of script calls (however many emails on screen) to setInnerHTML in it's own header on the page which are run on every postback so the email is correctly displayed during partial rendering.
Hopefully an fairly elegant solution to the problem - though no doubt someone will tell me otherwise :)
--------------------------- CODE ------------------------------.
function setInnerHTML(sCtlID, sStringCode)
{
var cCtl = dnn.dom.getById(sCtlID);
if (cCtl!=null)
{
cCtl.innerHTML = sStringCode;
}
}
Public Class MyAJAX
Private Shared m_Initialized As Boolean = False
Private Shared m_ScriptManagerType As Type
Private Shared Function ScriptManagerType() As Type
If m_ScriptManagerType Is Nothing Then
If Not m_Initialized Then
m_ScriptManagerType = DotNetNuke.Framework.Reflection.CreateType("System.Web.UI.ScriptManager", True)
End If
m_Initialized = True
End If
Return m_ScriptManagerType
End Function
Public Shared Sub RegisterStartupScript(ByVal objPage As Page, ByVal objControl As Control, ByVal sKey As String, ByVal sScript As String)
If Not ScriptManagerType() Is Nothing Then
If Not ScriptManagerControl(objPage) Is Nothing Then
DotNetNuke.Framework.Reflection.InvokeMethod(ScriptManagerType, "RegisterStartupScript", ScriptManagerControl(objPage), New Object() {objPage, objControl.GetType(), sKey, sScript, True})
End If
End If
End Sub
Public Shared Sub FixFormedStringCodeScript(ByVal objPage As Page, ByVal objControl As Control, ByVal sSCScript As String)
Dim nFindSC As Integer = sSCScript.ToLower.IndexOf("string.fromcharcode")
If nFindSC >= 0 Then
Dim sSCPart As String = sSCScript.Substring(nFindSC)
Dim nFindEnd As Integer = sSCPart.IndexOf(")"c)
If nFindEnd >= 0 Then
sSCPart = sSCPart.Substring(0, nFindEnd + 1)
RegisterStartupScript(objPage, objControl, objControl.ClientID, "setInnerHTML('" & objControl.ClientID & "'," & sSCPart & ");")
End If
End If
End Sub
End Class