0

我使用 ASP.NET 向导控件将新闻用户添加到我开发的基于 Web 的应用程序中。一切正常。现在,我从系统管理员那里得到了一个新要求,它正在向新用户发送电子邮件通知,告诉他他已被添加到系统中。我将邮件功能添加到我的代码中并且它可以工作,但是在 IE 浏览器中我注意到左下角的错误图标,我不知道为什么。

Problems with the Web page might prevent it from being displayed properly or functioning properly....
Line: 74
Char: 7
Error: Object Expected
Code: 0

那么如何消除这个错误呢?

带有邮件功能的代码隐藏:

 protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
    {
        //If one of the items is selected AND a username exists in the Username session object update the user role
        string username = TextBox1.Text;

        if (!String.IsNullOrEmpty(radio1.SelectedValue) && !String.IsNullOrEmpty(username))
        {
            string connString = "Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True";

            string insertUserCommand = "INSERT INTO employee (Name, Username, JobTitle, BadgeNo, EmpOrgType, DivisionCode) values (@Name, @Username, @JobTitle, @BadgeNo, @EmpOrgType, @DivisionCode)";
            string cmdText = "SELECT Count(*) FROM employee WHERE Username = '" + username + "'";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                // Open DB connection.
                using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                {
                    if ((int)cmd.ExecuteScalar() == 0){
                        .........................................
                    }

                }
            }

            //For updating the role of the user 
            string deleteCommand = "DELETE FROM UserRole where Username=@Username";
            string insertCommand = "INSERT INTO UserRole (RoleID,Username) values(@RoleID,@Username)";
            using (SqlConnection conn = new SqlConnection(connString))
            {
                conn.Open();
                //using (SqlCommand cmd = new SqlCommand(cmdText, conn))
                using (SqlCommand cmd = new SqlCommand(deleteCommand, conn))
                {
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //Now the insert
                    cmd.CommandText = insertCommand;
                    cmd.Parameters.Clear(); //need this because still has params from del comm
                    cmd.Parameters.AddWithValue("@RoleID", radio1.SelectedValue);
                    cmd.Parameters.AddWithValue("@Username", username);
                    cmd.ExecuteNonQuery();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                    //cmd.ExecuteScalar();
                    //infoSpan.InnerText = String.Format("The users role has been updated to - {0}", radio1.SelectedValue);
                }
            }

            Wizard1.Visible = false;
            wizard.InnerHtml = "...............";
        }

        Send(username);

    }
/*****************************************************/

    /*For sending an email */
    protected void Send(string toAddresses, string fromAddress, string MailSubject, string MessageBody, bool isBodyHtml)
    {
        SmtpClient sc = new SmtpClient("MailAddress");
        try
        {
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("test@mailAddress.com", "Test Sys.");

            msg.Bcc.Add(toAddresses);
            msg.Subject = MailSubject;
            msg.Body = MessageBody;
            msg.IsBodyHtml = isBodyHtml;
            sc.Send(msg);
        }
        catch (Exception ex)
        {
            throw ex;
        }

    }

    protected void SendEmailToUser(string username)
    {
        string connString = "Data Source=localhost;Initial Catalog=TestDB;Integrated Security=True";

        string networkID = username.ToString();

        using (SqlConnection conn = new SqlConnection(connString))
        {
            var sbEmailAddresses = new System.Text.StringBuilder(2000);

            //initiate the varibles that will be retreived from the database
            string name = null;

            // Open DB connection.
            conn.Open();

            string cmdText2 = @"SELECT     Name
                                FROM       dbo.employee
                                WHERE     (Username = @networkID)";
            using (SqlCommand cmd = new SqlCommand(cmdText2, conn))
            {
                cmd.Parameters.AddWithValue("@networkID", networkID);
                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    if (reader.Read())
                    {
                        name = reader["Name"].ToString();
                        sbEmailAddresses.Append(username).Append("@mailAddress.com");
                    }
                }

                //var sEMailAddresses = sbEmailAddresses.ToString();
                string body = "..........................";
                Send(sbEmailAddresses.ToString(), "", "Welcome", body, true);
                sbEmailAddresses.Clear();

            }

            conn.Close();
        }
    }
4

1 回答 1

0
于 2012-07-21T07:00:49.683 回答