I have been asked to fix a piece of legacy code that doesn't work. I don't know whether this ever worked, but it looks OK to me as per the documentation and examples.
Our InfoPath form uses the 2003 object model. Its FormCode.cs calls other assemblies one of which contains the line:
moderatorId = (string)thisXDocument.UI.ShowModalDialog("UserNamePasswordDialog.htm", thisXDocument, 200, 400, Type.Missing, Type.Missing);
UserNamePasswordDialog.htm is one of the form's Resources files that gets correctly packaged into the final XSD file. Within this HTML file is script which I have enhanced with some diagnostic tests as follows:
<script language="jscript" type="text/jscript">
var gobjXDocument = null;
var moderatorId = null;
function Initialize()
{
// Save a reference to the XDocument object.
if (typeof window.dialogArguments == "object")
{
gobjXDocument = window.dialogArguments;
}
else
{
if (null == window.dialogArguments)
{
window.alert("window.dialogArguments is null!");
}
else
{
gobjXDocument = window.dialogArguments;
}
}
if (null == gobjXDocument)
{
window.alert("gobjXDocument is null!");
}
else
{
if (null == gobjXDocument.Extension)
{
window.alert("gobjXDocument.Extension is null!");
}
}
}
function Close()
{
//if username or password is blank give val msg in error
if(UserNameid.value == "")
{
errorid.innerText = "Please enter a username.";
errorid.style.display = '';
}
else
{
//if username and password are not blank and are valid for this action return and close
moderatorId = gobjXDocument.Extension.Logon(UserNameid.value, Passwordid.value)
if(moderatorId)
{
//if email is not blank return email and close
window.returnValue = moderatorId;
// Close the dialog
window.close();
}
else
{
errorid.innerText = "The username and password are not valid !";
errorid.style.display = '';
}
}
}
</script>
Any time this is run the Initialize method throws up the alerts "window.dialogArguments is null!" and "gobjXDocument is null!". The latter is obviously expected given the occurrence of the former.
The pertinent questions are of course why is this happening and how do I fix it?
From browsing various forums I have learned that the most common reason for window.dialogArguments to come through as null is when one is making the ShowModalDialog call cross domain. In this scenario this clearly cannot ever be the case since the form's embedded code is calling one of its own embedded resource files. However, that cross domain business is clearly a security feature so I'm wondering whether there is some other security feature that's causing the issue in my case. My form is configured such that it requires Full Trust. To my understanding this does not actually kick in when running via the debugger (which I am doing), and besides that I have also built the form and signed it and I still get the same result when I run that version.
So, any ideas anyone?
Regards,
Michael