InvalidOperationException未被用户代码处理。 [英] InvalidOperationException was Unhandled by user code.
问题描述
我在几天内处理我的项目但是当我尝试在屏幕上显示消息框时我遇到错误,否则不会产生错误..
这每个消息框打印行都会出错。
错误名称为"InvalidOperationException未被用户代码处理"
消息是"当应用程序未在UserInteractive模式下运行时显示模式对话框或表单不是有效操作。指定SerciceNotification或 DefaultDesktopOnly样式,以显示从服务应用程序的通知"
和我的代码是糊这里..
使用System;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Web;
使用System.Web.Security;
使用System.Web.UI;
使用System。 Web.UI.WebControls;
。使用System.Web.UI.WebControls.WebParts;使用
System.Web.UI.HtmlControls;
公共部分类付款详情:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
//lblusersessionname.Text = Session [" username"]。ToString();
}
int i;
protected void Button1_Click(object sender,EventArgs e)
{
if(会话[" total"]!= null)
{
i =(int)会话[" total"];
if(i> 0)
{
Com.Recruitment.DataBase.Connection.Connection con = Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection();
  ;    DataSet ds = con.getDataSet(" select * from cartdetail,其中ccno =" + TextBox1.Text +" and acountno =" + TextBox2.Text +" and password ='" + TextBox10.Text +" '");
$
if(ds.Tables [0] .Rows.Count> 0)
   {
如果(Convert.ToInt32(ds.Tables [0] .Rows [0] [5])>(int)的会话["总"])
                     {
                    &NBSP ;   System.Windows.Forms.DialogResult DG = System.Windows.Forms.MessageBox.Show("您可以purchase.Are确定"?);
    &NBSP ;                  如果(DG == System.Windows.Forms.DialogResult.OK)
             &NBSP ;          {
                    &NBSP ;       int k = Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection()。ExecuteNonQuery(" update
cartdetail set total = total-" + i +" where ccno =" + TextBox1.Text +" ;");
                  &NBSP ;         DataSet ds1 = Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection()。getDataSet(" select
* from cartdetail");
                       System.Windows.Forms.MessageBox.Show(" your current balance is" + ds1.Tables [0] .Rows [0] [5] .ToString());
}
                    &NBSP ;  否则
                    &NBSP ;   {
                &NBSP ;           System.Windows.Forms.MessageBox.Show("抱歉!你有更少的金额");
$
;                     }
}
}
否则b $ b {
System.Windows.Forms.MessageBox.Show(" Your intmamations not corrent);
$
     }
}
否则为
{
System.Windows.Forms.MessageBox.Show(QUOT;首先购买产品");
       &NBSP ;    }
}
}
}
请帮助我!!
并在我的Gmail帐户中发送解决方案gptgaurav04@gmail.com
谢谢......
'p>
您不能使用Windows窗体在网页中的MessageBox。
请使用http://forums.asp.net/获取与ASP.NET相关的问题,此论坛适用于C ++语言问题。
I m working on my project in few days but i face the error when i try to show the message box in the screen else not create a error..
This error occur every Message box print line..
Error name is "InvalidOperationException was Unhandled by user code"
Message is "Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the SerciceNotification or DefaultDesktopOnly style to display a notification from a service application."
and my code is paste here..
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class paymentdetail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//lblusersessionname.Text = Session["username"].ToString();
}
int i;
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["total"] != null)
{
i = (int)Session["total"];
if (i > 0)
{
Com.Recruitment.DataBase.Connection.Connection con= Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection();
DataSet ds= con.getDataSet("select * from cartdetail where ccno=" + TextBox1.Text + " and acountno=" + TextBox2.Text + " and password='" + TextBox10.Text + "'");
if (ds.Tables[0].Rows.Count > 0)
{
if (Convert.ToInt32(ds.Tables[0].Rows[0][5]) > (int)Session["total"])
{
System.Windows.Forms.DialogResult dg = System.Windows.Forms.MessageBox.Show("you can purchase.Are you sure?");
if (dg == System.Windows.Forms.DialogResult.OK)
{
int k = Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection().ExecuteNonQuery("update
cartdetail set total=total- " + i + " where ccno=" + TextBox1.Text + "");
DataSet ds1 = Com.Recruitment.DataBase.Connection.ConnectionPool.getConnection().getDataSet("select
* from cartdetail");
System.Windows.Forms.MessageBox.Show("your current balance is" + ds1.Tables[0].Rows[0][5].ToString());
}
else
{
System.Windows.Forms.MessageBox.Show("Sorry!you have less amount");
}
}
}
else
{
System.Windows.Forms.MessageBox.Show("Your inormations are not corrent");
}
}
else
{
System.Windows.Forms.MessageBox.Show("First purchase a product");
}
}
}
}
please help me!!
and send the solution in my gmail account gptgaurav04@gmail.com
Thanks...
You cannot use a Windows Forms MessageBox in a web page.
Please use http://forums.asp.net/ for questions related to ASP.NET, this forum is for C++ language questions.
这篇关于InvalidOperationException未被用户代码处理。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!