protected void btnAddBlog_Click(object sender, EventArgs e)
    {
        string title       = txtBlogtitle.Text;
        string description = CKEditor1.Text.Trim();
        //int categoryid = Convert.ToInt32(ddCategory.SelectedValue);
        string date   = DateTime.Now.ToString("dd/MM/yyyy");
        int    result = 0;

        try
        {
            //if (string.IsNullOrEmpty(Convert.ToString(Session["blogid"])))
            if (string.IsNullOrEmpty(Convert.ToString(ViewState["ID"])))
            {
                string blogimage = "";
                if (UploadImage.HasFile)
                {
                    string imgPath = "~/Upload/blog/";
                    //string thumbPath = "~/Upload/thumbnails/";

                    string ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName));
                    blogimage = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile;
                    //thumbPath = thumbPath + blogimage;
                    System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream);
                    System.Drawing.Image  objImage         = ScaleImage(bmpUploadedImage, 300);
                    //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage);
                    //objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png);

                    imgPath = imgPath + blogimage;
                    UploadImage.SaveAs(MapPath(imgPath));
                }


                result = local_product.AddNewBlog(title, description, date, blogimage);

                if (result != 0)
                {
                    lblMessage.Text      = "New blog added";
                    lblMessage.ForeColor = Color.Green;
                    BindBlog();
                    txtBlogtitle.Text = "";
                    CKEditor1.Text    = "";
                }
                else
                {
                    lblMessage.Text      = "Blog not added?";
                    lblMessage.ForeColor = Color.Red;
                }
            }
            else //edit
            {
                string blogimage = "";
                if (UploadImage.HasFile)
                {
                    string imgPath = "~/Upload/blog/";
                    //string thumbPath = "~/Upload/thumbnails/";

                    string ImageFile = Path.GetFileName(Server.MapPath(UploadImage.PostedFile.FileName));
                    blogimage = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "-" + ImageFile;
                    //thumbPath = thumbPath + blogimage;
                    System.Drawing.Bitmap bmpUploadedImage = new System.Drawing.Bitmap(UploadImage.PostedFile.InputStream);
                    System.Drawing.Image  objImage         = ScaleImage(bmpUploadedImage, 300);
                    //System.Drawing.Image objImage = ScaleImage(bmpUploadedImage);
                    //objImage.Save(Server.MapPath(thumbPath), ImageFormat.Png);

                    imgPath = imgPath + blogimage;
                    UploadImage.SaveAs(MapPath(imgPath));
                }
                else
                {
                    blogimage = lblImage.Text;
                }

                string blogid = Request.QueryString["blogid"];
                result = local_product.UpdateBlog(title, description, blogid, blogimage);

                if (result != 0)
                {
                    lblMessage.Text      = "Blog updated successfully";
                    lblMessage.ForeColor = Color.Green;
                    BindBlog();
                    txtBlogtitle.Text = "";
                    CKEditor1.Text    = "";
                    Session["blogid"] = null;
                    Session["ID"]     = null;
                    btnAddBlog.Text   = "Add Blog";
                    lblImage.Text     = "";
                }
                else
                {
                    lblMessage.Text      = "Blog not updated?";
                    lblMessage.ForeColor = Color.Red;
                }
            }
        }
        catch (Exception ex)
        { throw new Exception(ex.Message); }
    }