0

I'm trying to assign a text value to a literal inside a catch block I tried this code but in exception its passing null value to Literal1.Text

         public partial class leadsmg : System.Web.UI.Page
{...
    [WebMethod]
    [ScriptMethod]
    public static void Savecmp(Cmpdet user)
    {
        leadsmg ld = new leadsmg();
        string user_Id = HttpContext.Current.Session["id"].ToString();
        SqlConnection conn = new SqlConnection(HttpContext.Current.Session["ConnectionString"].ToString());

        SqlCommand cmd = new SqlCommand("insert into companydet (cname,caddr,cweb,cpno,ccd,uid,cad)values(@Cname,@Caddr,@Cweb,@Cpnno,@Cdate,@Uid,getdate())");

        try
        {
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@Cname", user.Cname);
            cmd.Parameters.AddWithValue("@Caddr", user.Caddr);
            cmd.Parameters.AddWithValue("@Cweb", user.Cweb);
            cmd.Parameters.AddWithValue("@Cpnno", user.Cpno);
            cmd.Parameters.AddWithValue("@Cdate", user.Cdateadd);
            cmd.Parameters.AddWithValue("@Uid", user_Id);
            cmd.Connection = conn;
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();

        }
        catch (Exception e)
        {
            conn.Close();
            ld.Literal1.Text = "Company already exits";//here its passing null value to Literal1.Text
        }
    }.....}

leadsmg is the main method where Savecmp exists.

how to resolve this problem?

555
  • 147
  • 8
Suhas
  • 83
  • 2
  • 17

0 Answers0