Reputation: 1533
I have a javascript function like below.
var object;
$(document).ready(function () {
$("#buttonA").click(function (e) {
object.doWork(); //triggers a method in Silverlight
});
});
Method in Silverlight
private void doWork()
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.ShowDialog(); //throws error "Dialogs must be user-initiated"
}
Any ideas why the error is thrown. I do not have any break points set in the doWork method in silverlight. The button click event in javascript seems to be user initiated event. Please suggest a solution to this problem.
Thanks,
Upvotes: 0
Views: 176
Reputation: 2241
Dialogs must be user-initiated in the sense that they have to occur due to a user interaction event (click, button press etc) within the Silverlight component. (In fact "due to" is really a restriction of having to occur within a certain period after the interaction, rather than some strict restriction such as relating to the call stack)
From the perspective of the Silverlight security restriction, this is just an arbitrary javascript method calling into Silverlight, and so this will not be possible (for good reason). You would need to open the dialog from a real Silverlight button.
If you really need to raise some kind of dialogs from a Silverlight control called via javascript, you may need to actually call back out to open a dialog in JavaScript/HTML (or some kind of popover in either environment).
Upvotes: 2