Click here to Skip to main content
15,886,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void btnsubmit_Click(object sender, EventArgs e)
  {
      try
      {
          if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
                  {
                      DateTime dob = new DateTime();
                      dob = DateTime.Parse(txtdob.Text, Cul, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

                      DateTime doj = new DateTime();
                      doj = DateTime.Parse(txtdoj.Text, Cul, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

          obj.dob = dob.ToShortDateString();
          obj.doj =doj.ToShortDateString();



                    if (FileUpload1.HasFile)
                      {

                          filename = Path.GetFileName(FileUpload1.PostedFile.FileName);

                          //filename = FileUpload1.PostedFile.FileName;
                          Boolean stat = System.IO.File.Exists(Request.PhysicalApplicationPath + "/Upload/" + filename);
                          if (stat == true)
                          {
                              var chars1 = "abcdefghijklmnopqrstuvwxyz0123456789";
                              var Randomchar = new Random();
                              var reschar1 = new string(Enumerable.Repeat(chars1, 3).Select(n => n[Randomchar.Next(n.Length)]).ToArray());
                              filename = reschar1 + ".jpg";
                          }

                          //string targetPath = Server.MapPath("../Upload/" + filename.ToString());
                          //Stream strm = FileUpload1.PostedFile.InputStream;
                          //var targetFile = targetPath;

                          FileUpload1.SaveAs(Server.MapPath("../Upload/" + filename));
                          obj.photo = "../Upload/" + filename.ToString();
                      }
                      obj.Type = 3;
                      result = obj.Execute();
                      if (result > 0)
                      {
                          GetCustomercode();
                          msg.ShowAlertMessage("Inserted Successfully");
                          clear();

                      }

                  }
                  else
                  {
                      msg.ShowAlertMessage("select Image");
                  }
                  Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
              }

      catch (Exception ex)
      {
          Response.Write(ex.ToString());
      }

  }


1.My execution not entering into if(fileupload1.Hasfile)
2.If the condition without fileupload it didnt take any dates. 1/1/2015,1/1/2015 it will take the value.
main prob is fileupload.
Posted

1 solution

if you use update panel then use Triggers Element Reference
 
Share this answer
 
Comments
Arasappan 16-Jul-15 7:24am    
<pre> <Triggers>
<asp:PostBackTrigger ControlID="btnsubmit" />
<asp:PostBackTrigger ControlID="btncancel" />
</Triggers></pre>

Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900