0

在我的 aspx 移动页面中,当我向服务器发送 ajax 请求时出现此错误:

Sys.ArgumentTypeException: Object of type 'AjaxControlToolkit.ModalPopupBehavior' cannot  be converted to type 'AjaxControlToolkit.ModalPopupBehavior'. Parameter name: instance

我不知道到底发生了什么,但我确信它与我页面中的 jquery 有关,因为我检查了这个页面而不包括 jqm 并且它工作正常。谢谢

在 asp 页面中单击按钮时运行的行:

string message = "blahbalahblahblah...";
MessageBoxInfo.Show(MessageBox.MessageType.Error, message, 110, 350);
return;

在我的 Control(MessageBox.ascx) 我有:

<asp:LinkButton ID="LinkButtonTargetControl" runat="server"></asp:LinkButton>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderMessage" runat="server" TargetControlID="LinkButtonTargetControl" 
    PopupControlID="MessageBox" OkControlID="ButtonOK" CancelControlID="CloseButton" BackgroundCssClass="messagemodalbackground" />

    <asp:Panel ID="MessageBox" runat="server" style="display:none;">
         <asp:HyperLink runat="server" id="CloseButton" >
            <asp:Image ID="Image1" runat="server"  ImageUrl="../images/Message/close.png" AlternateText="Close" />
        </asp:HyperLink>
        <p><asp:Literal ID="litMessage" runat="server"></asp:Literal></p>
    </asp:Panel>      

显示方法如下(MessageBox.ascx.cs):

public void Show(MessageType messageType, string message, int height, int width)
{
    CloseButton.Visible =  ShowCloseButton;
    litMessage.Text = message;
    MessageBox.Height = height;
    MessageBox.Width = width;
    MessageBox.CssClass = messageType.ToString().ToLower();
    ModalPopupExtenderMessage.Show();
    this.Visible = true;
}

另外我应该提到,每次调用的 show 方法以及其中的所有内容,例如宽度高度......设置好,但如果你在萤火虫中检查它,你会看到 display:none 仍然存在!

4

1 回答 1

0

For some reason the runtime is supposed to use two different assemblies called AjaxControlToolkit.ModalPopupBehavior, let's say AjaxControlToolkit.ModalPopupBehavior1 and AjaxControlToolkit.ModalPopupBehavior2.

MessageBoxInfo is coming from AjaxControlToolkit.ModalPopupBehavior1 and
MessageBox.MessageType is coming from AjaxControlToolkit.ModalPopupBehavior2

So the MessageBoxInfo.Show(MessageBox.MessageType.Error, message, 110, 350); throws a fake conversion error.

If you try another Show() override, without MessageBox.MessageType it works, true?

Real solution, if you can't find the reasom could be a workaround using reflection: to get the assemlby at runtime from MessageBoxInfo object
and using it to instantiate a MessageBox.MessageType.

于 2012-10-01T11:27:33.853 回答