Question

Locked

'ContactControl.SmtpClient.OnInit(System.EventArgs)':no suitable method fou

By garrie ·
Hi All,

I am fairly new to C# development and i am trying to build a contact page with title,forename,surname,etc (this my first web user control of this type) i use VSTS2005 and no matter what i do i keep getting the following message in the error box, and the code highlighted is "OnInit" in the region. Thanks in advance, all help will be appreciated.

'ContactControl.SmtpClient.OnInit(System.EventArgs)':no suitable method found to ovrride.

Code below:


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;
using System.Net.Mail;
using System.Messaging;


public partial class ContactControl : System.Web.UI.UserControl
{

public class SmtpClient
{

protected void Page_Load(System.Object sender, System.EventArgs e)
{

lblResult.Text = "";
lblResult.Visible = false;
}


protected void Button1_Click(System.Object sender, System.EventArgs e)
{
// check input
bool isOK = true;
lblResult.Visible = true;

if (TxtTitle.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your Title.";
isOK = false;
}

if (TxtForename.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your Forename.";
isOK = false;
}

if (TxtSurname.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your Surname.";
isOK = false;
}

if (TxtEvening.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your evening number.";
isOK = false;
}

if (TxtDaytime.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your daytime number.";
isOK = false;
}

if (TxtMobile.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your mobile number.";
isOK = false;
}

if (TxtAddress1.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter the first line of your address.";
isOK = false;
}

if (TxtAddress2.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter the sceond line of your address.";
isOK = false;
}

if (TxtAddress3.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter the third line of your address.";
isOK = false;
}

if (TxtTown.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your Town.";
isOK = false;
}

if (TxtCounty.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your County.";
isOK = false;
}

if (TxtPostcode.Text.Trim() + "" == "")
{
lblResult.Text = "Please enter your Postcode.";
isOK = false;
}

if (TxtEmail.Text.Trim() + "" == "" | TxtEmail.Text.IndexOf("@") < 1 | TxtEmail.Text.IndexOf(".") < 2)
{
lblResult.Text = "Please enter a valid e-mail address.";
isOK = false;
}

if (!(isOK))
{
return;
}

// send message
try
{
SendMail(TxtEmail.Text, "mail@prologicsolutionsit.com", "", @"<html><body style=""font-family:arial"">From: " + Server.HtmlEncode(TxtForename.Text + " (" + TxtEmail.Text + ")"));
lblResult.Text = "Thank you for your message. We will contact you soon.";
// clear form
TxtTitle.Text = "";
TxtForename.Text = "";
TxtSurname.Text = "";
TxtEvening.Text = "";
TxtDaytime.Text = "";
TxtEvening.Text = "";
TxtMobile.Text = "";
TxtAddress1.Text = "";
TxtAddress2.Text = "";
TxtAddress3.Text = "";
TxtTown.Text = "";
TxtCounty.Text = "";
TxtPostcode.Text = "";
TxtEmail.Text = "";
TxtMessage.Text = "";
}
catch (Exception ex)
{
lblResult.Text = "Sorry, your message couldn't be sent due to the following error: " + ex.Message;
}
}

public void SendMail(
string TxtTitle,
string TxtForename,
string TxtSurname,
string TxtEvening,
string TxtDaytime,
string TxtMobile,
string TxtAddress1,
string TxtAddress2,
string TxtAddress3,
string TxtCounty,
string TxtPostcode,
string TxtEmail,
string TxtMessage,
string body
)
{

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.Body = TxtTitle;
msg.Body = TxtForename;
msg.Body = TxtSurname;
msg.Body = TxtEvening;
msg.Body = TxtDaytime;
msg.Body = TxtMobile;
msg.Body = TxtAddress1;
msg.Body = TxtAddress2;
msg.Body = TxtAddress3;
msg.Body = TxtCounty;
msg.Body = TxtPostcode;
msg.Body = TxtEmail;
msg.Body = TxtMessage;
System.Net.Mail.SmtpClient = new System.Net.Mail.SmtpClient(SmtpClient);
System.Net.Mail.SmtpClient.Send(msg);

}

#region " Web Form Designer Generated Code "
protected override void OnInit(EventArgs e)
{
this.Button1_Click += new System.Object.EventHandler(this.Button1_Click);
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
}

#endregion

}

}

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Windows Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums