protected void Binsert_Click(object sender, EventArgs e) { if (ValidateProductData() == true) { //HttpContext.Current.Response.Write("<script>alert('validity true Added product " + Insertname.Text + "')</script>"); try { try { string fileName = Path.GetFileName(insertImageFile.PostedFile.FileName); insertImageFile.PostedFile.SaveAs(Server.MapPath("~/images/") + fileName); uploadPicture.Text = fileName; } catch { HttpContext.Current.Response.Write("<script>alert('File upload Error')</script>"); return; } try { SqlDataSourceInsertProduct.Insert(); } catch { HttpContext.Current.Response.Write("<script>alert('SQL Error Added product " + Insertname.Text + "')</script>"); return; } HttpContext.Current.Response.Write("<script>alert('Successfully Added product " + Insertname.Text + "')</script>"); Insertname.Text = ""; Insertprice.Text = ""; Insertdiscount.Text = ""; Insertcolor.Text = ""; Insertsize.Text = ""; Insertcatogory.Text = ""; Insertbrand.Text = ""; Insertdescription.Text = ""; insertinformation.Text = ""; Insertrate.Text = ""; Inserttag.Text = ""; Insertsku.Text = ""; } catch (Exception err) { HttpContext.Current.Response.Write("<script>alert('Not able to Added product " + Insertname.Text + "\n" + err.Message + "')</script>"); return; } } else { HttpContext.Current.Response.Write("<script>alert('Invalid inputs')</script>"); return; } }
protected void Binsert_Click(object sender, EventArgs e) { if (ValidateProductData() == true) { //HttpContext.Current.Response.Write("<script>alert('validity true Added product " + Insertname.Text + "')</script>"); try { try { string fileName = null; // reading the image from disk and uploading to server fileName = Path.GetFileName(FileUpload0.PostedFile.FileName); // read file FileUpload0.PostedFile.SaveAs(Server.MapPath("~/images/") + fileName); // save to server uploadPicture.Text = fileName.Split('.')[0]; // store filename fileName = Path.GetFileName(FileUpload1.PostedFile.FileName); // read file FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") + fileName); // save to server uploadPicture.Text = uploadPicture.Text + ',' + fileName.Split('.')[0]; // store filename fileName = Path.GetFileName(FileUpload2.PostedFile.FileName); // read file FileUpload2.PostedFile.SaveAs(Server.MapPath("~/images/") + fileName); // save to server uploadPicture.Text = uploadPicture.Text + ',' + fileName.Split('.')[0]; // store filename } catch { HttpContext.Current.Response.Write("<script>alert('File upload Error')</script>"); return; } try { // performing sal insert operation SqlDataSourceInsertProduct.Insert(); } catch { HttpContext.Current.Response.Write("<script>alert('SQL Error Added product " + Insertname.Text + "')</script>"); return; } HttpContext.Current.Response.Write("<script>alert('Successfully Added product " + Insertname.Text + "')</script>"); // after successful insertion - clearing all the entries Insertname.Text = ""; Insertprice.Text = ""; Insertdiscount.Text = ""; Insertcolor.Text = ""; Insertsize.Text = ""; Insertcatogory.Text = ""; Insertbrand.Text = ""; Insertdescription.Text = ""; insertinformation.Text = ""; Insertrate.Text = ""; Inserttag.Text = ""; Insertsku.Text = ""; } catch (Exception err) { HttpContext.Current.Response.Write("<script>alert('Not able to Added product " + Insertname.Text + "\n" + err.Message + "')</script>"); return; } } else { HttpContext.Current.Response.Write("<script>alert('Invalid inputs')</script>"); return; } }