当应用程序未在UserInteractive模式下运行时显示模式对话框或表单不是有效操作

时间:2011-11-14 08:00:57

标签: c# asp.net web-applications

当我想在远程服务器上读取.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(String text,String caption,MessageBoxButtons buttons,MessageBoxIcon icon,MessageBoxDefaultButton defaultButton)+25      C:\ Documents and Settings \ yeohs \ Desktop \ NetWorkInformationSystem \ NetWorkInformationSystem \ classes \ ReadExcelFile.cs中的NetWorkInformationSystem.classes.ReadExcelFile.GetDataFromExcelPatchRecordRead(String filename):62      NetWorkInformationSystem.PatchRecords.ConfirmBtn_Click(Object sender,EventArgs e)在C:\ Documents and Settings \ yeohs \ Desktop \ NetWorkInformationSystem \ NetWorkInformationSystem \ forms \ PatchRecords.aspx.cs:121      System.Web.UI.WebControls.Button.OnClick(EventArgs e)+111      System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)+110      System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String 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();
}

**

  

嘿PROS !!任何在服务器上显示选项消息框的重要解决方案   提供?好的,取消? YES,NO?

**

1 个答案:

答案 0 :(得分:0)

总结通过评论发生的事情,

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

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

  

但是应该读取的数据不会添加到数据库中!可能是什么   因为现在?

您需要调试并查看GICdatabase.InsertRecords(listofDataSet);

中发生的情况

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