k k

k k

  • NA
  • 1
  • 784

nullreferenceexception was unhandled by user code

Mar 8 2016 12:21 PM

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Security.Cryptography;

using System.Text;

using System.Net.Mail;

using System.Data.SqlClient;

using System.Configuration;

public partial class _Default : System.Web.UI.Page

{

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RCCon"

 

].ConnectionString); //error

ullreferenceexception was unhandled by user code

 
SqlCommand cmd;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

setimageurl();

}

}

protected void Timer1_Tick(object sender, EventArgs e)

{

setimageurl();

}

private void setimageurl()

{

if (ViewState["ImageDisplayed"] == null)

{

Image1.ImageUrl = "~/img/1.jpg";

ViewState["ImageDisplayed"] = 1;

}

else

{

int i = (int)ViewState["ImageDisplayed"];

if (i == 8)

{

Image1.ImageUrl = "~/img/1.jpg";

ViewState["ImageDisplayed"] = 1;

}

else

{

i++;

Image1.ImageUrl = "~/img/" + i.ToString() + ".jpg";

ViewState["ImageDisplayed"] = i;

}

}

}

public void Send_Account_Activation_Link(string emailaddress, string act_code)

{

MailMessage mm = new MailMessage("Your EMail ID", emailaddress);

mm.Subject = "Account Activation";

string body = "Hello " + txtusername.Text + ",";

body += "Please click the following link to activate your account";

body += "Click here to activate your account.";

body += "Thanks";

mm.Body = body;

mm.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);

smtp.Credentials = new System.Net.NetworkCredential("Your Email ID", "");

smtp.EnableSsl = true;

smtp.Send(mm);

}

protected void Button1_Click(object sender, EventArgs e)

{

Response.Write("Your Registration Is Successful");

}

protected void Btn_Register_Click(object sender, EventArgs e)

{

string activationCode = Guid.NewGuid().ToString();

string encry_password = Encrypt_Password(txtpassword.Text);

cmd = new SqlCommand("insert into Registration values('" + txtusername.Text.ToLower() + "','" + encry_password + "','" + txtemailid.Text + "','" + activationCode + "','inactive')");

cmd.Connection = con;

con.Open();

cmd.ExecuteNonQuery();

Send_Account_Activation_Link(txtemailid.Text, activationCode);

con.Close();

Session["user"] = txtusername.Text;

Response.Redirect("Account_Activation.aspx");

}

private string Encrypt_Password(string password)

{

string pwdstring = string.Empty;

byte[] pwd_encode = new byte[password.Length];

pwd_encode = Encoding.UTF8.GetBytes(password);

pwdstring = Convert.ToBase64String(pwd_encode);

return pwdstring;

}

}
 
 
 
Please help what should I do ???????

Answers (6)