【问题标题】:Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation当应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作
【发布时间】:2011-11-14 08:00:56
【问题描述】:

当我想在远程服务器上读取 .xlsx excel 文件时遇到此错误,但奇怪的是不在本地计算机上。我尝试将代码从 MessageBox.Show(mymessage) 更改为
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + mymessage+ " ');", true);

然后我意识到,即使我注释掉所有显示消息 msgbox/alert,我仍然会面临同样的错误。

源错误:在执行当前 Web 请求期间产生了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

堆栈跟踪 [InvalidOperationException:当应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作。指定 ServiceNotification 或 DefaultDesktopOnly 样式以显示来自服务应用程序的通知。] System.Windows.Forms.MessageBox.ShowCore(IWin32Window 所有者,字符串文本,字符串标题,MessageBoxButtons 按钮,MessageBoxIcon 图标,MessageBoxDefaultButton defaultButton,MessageBoxOptions 选项,Boolean showHelp)+2661826 System.Windows.Forms.MessageBox.Show(字符串文本,字符串标题,MessageBoxButtons 按钮,MessageBoxIcon 图标,MessageBoxDefaultButton defaultButton)+25 C:\Documents and Settings\yeohs\Desktop\NetWorkInformationSystem\NetWorkInformationSystem\classes\ReadExcelFile.cs:62 中的 NetWorkInformationSystem.classes.ReadExcelFile.GetDataFromExcelPatchRecordRead(字符串文件名) C:\Documents and Settings\yeohs\Desktop\NetWorkInformationSystem\NetWorkInformationSystem\forms\PatchRecords.aspx.cs:121 中的 NetWorkInformationSystem.PatchRecords.ConfirmBtn_Click(Object sender, EventArgs e) System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111 System.Web.UI.WebControls.Button.RaisePostBackEvent(字符串 eventArgument)+110 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

listofTableTable = ReadExcelFile.GetDataFromExcelPatchRecordRead(filename);
listofDataSet = ReadListOfDataFromExcelPatchRecord(listofTableTable);

    if (listofDataSet.Count >= 1)
    {
    //insert according by filename
    int deletecount = GICdatabase.InsertRecords(listofDataSet);
}

读取记录

    foreach (DataRow dr in listofTableTable.Rows)
{
string a= dr["a"].ToString().ToUpper().Trim();
string b= dr["b"].ToString().ToUpper().Trim();
string c= dr["c"].ToString().ToUpper().Trim();
string d= dr["d"].ToString().ToUpper().Trim();
string e= dr["e"].ToString().Trim();
string f= dr["f"].ToString().ToUpper().Trim();
string g= dr["g"].ToString().ToLower().Trim();
string h= dr["h"].ToString().ToLower().Trim();
string i= dr["i"].ToString().ToLower().Trim();
string j= dr["j"].ToString().ToLower().Trim();
DateTime datestamp =DateTime.Now.ToLocalTime();
}

**

嘿专业人士!在服务器上显示选项消息框的任何出色解决方案 提供?例如确定,取消?是,不是?

**

【问题讨论】:

  • 该错误与您读取 .xlsx 文件的方式有关。发布该代码可能会有所帮助。
  • 嘿,感谢您的回复,但我觉得这很奇怪! y没有在远程服务器上显示消息,但在本地机器上完全没问题。我还有一些其他问题,例如显示用户名(UserPrincipal.Current.DisplayName)以及导出 excel 模板。但现在我只想解决这个问题......
  • 在原始错误中,它谈到了堆栈跟踪..你有吗?
  • 嘿,是的!刚刚编辑。您认为可能是什么原因?
  • 一个问题可能是您尝试在 Web 代码中使用 MessageBox.Show()。这是显示消息的 win-forms 方式,不能在 web 中这样做。你说过,即使你把它注释掉,你仍然会得到同样的错误?它是否具有相同的堆栈跟踪? (我怀疑)

标签: c# asp.net web-applications


【解决方案1】:

所以总结一下通过cmets发生的事情,

嘿,是的!刚刚编辑。你认为可能是什么原因?

一个问题可能是您尝试在网络中使用 MessageBox.Show() 代码。这是显示消息的win-forms方式,不能这样做 网络方式。

但是应该读取的数据没有添加到数据库中!可能是什么 导致现在?

这个你需要调试一下,看看GICdatabase.InsertRecords(listofDataSet);会发生什么

注意:看起来您正在以错误的方式(win-forms 策略)实现 Web 应用程序,这是不正确的。我建议您阅读一些 asp.net 文章并首先了解根本差异。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    相关资源
    最近更新 更多