Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi in my asp.net page i m using file upload control to upload file...

but when i am selecting any file and.. clicking on save button....
then my button click event not firing...

if i donot select any file in file upload control then clicking on save...

then event is firing...

i not able to understand where is the problem....

plse Help me.....

This is my button click code...


C#
protected void Btn_Save_Click(object sender, EventArgs e)
   {
       try
       {

           if (Btn_Save.Text == "Update")
           {
               bool dis_sts;
               if (Chk_Dispos.Checked)
               {

                   dis_sts = true;
                   ProductProvider.Update_Fixed_Asset(ID, dis_sts, Convert.ToDateTime(Txt_Dis_Dt.Text).Date, (Convert.ToDouble((Txt_DisposValue.Text == "") ? "0" : Txt_DisposValue.Text)));
                   ProductProvider.Insert_JournalEntry(Convert.ToDateTime(Txt_Dis_Dt.Text).Date, "DISP", Convert.ToInt32(ddlAccrunalNominalAC.Items.FindByText("Asset Disposal").Value), ddlLocations.SelectedValue, "Fixed Asset", Convert.ToInt32("0"), (Convert.ToDouble((Txt_DisposValue.Text == "") ? "0" : Txt_DisposValue.Text)), Convert.ToDouble("0"), 0, "Null", Txt_Ref.Text, DateTime.Now, "none", DateTime.Now, 0);

               }
               else
               {
                   dis_sts = false;
               }
           }
           else
           {
               //    Upload Image

               string tempfile = null;
               string fullname = null;
               if (File_UP_Img.HasFile)
               {
                   tempfile = Path.GetFileName(File_UP_Img.FileName);
                   File_UP_Img.SaveAs(Server.MapPath("~/Upload_Asset/") + tempfile);

                   fullname = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + Txt_Ref.Text + "_" + tempfile;
                   File.Move(Server.MapPath("~/Upload_Asset/") + tempfile, Server.MapPath("~/Upload_Asset/") + fullname);
                   // FileUploadControl.SaveAs(Server.MapPath("~/") + filename);

               }

               //    Upload Document1

               string tempfile1 = null;
               string fullname1 = null;
               if (FileUpload1.HasFile)
               {
                   tempfile1 = Path.GetFileName(FileUpload1.FileName);
                   FileUpload1.SaveAs(Server.MapPath("~/Upload_Asset/") + tempfile1);

                   fullname1 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_" + Txt_Ref.Text + "_" + tempfile1;
                   File.Move(Server.MapPath("~/Upload_Asset/") + tempfile1, Server.MapPath("~/Upload_Asset/") + fullname1);
                   // FileUploadControl.SaveAs(Server.MapPath("~/") + filename);

               }



               ////    Upload Document2

               string tempfile2 = null;
               string fullname2 = null;


               DateTime Date_Pu = Convert.ToDateTime(txtDate_pur.Text).Date;
               DateTime Date_capt = Convert.ToDateTime(Txt_DTCP.Text).Date;
               DateTime Date_exp = Convert.ToDateTime(Txt_Expiry_dt.Text).Date;
               DateTime Date_dis = Convert.ToDateTime(Txt_Dis_Dt.Text).Date;
               double deplif = 0;
               double deprat = 0;
               bool dis_sts;
               string meth = null;

               if (Chk_Dispos.Checked)
               {
                   dis_sts = true;
                   ProductProvider.Insert_JournalEntry(Convert.ToDateTime(Txt_Dis_Dt.Text).Date, "DISP", Convert.ToInt32(ddlAccrunalNominalAC.Items.FindByText("Asset Disposal").Value), ddlLocations.SelectedValue, "Fixed Asset", Convert.ToInt32("0"), (Convert.ToDouble((Txt_DisposValue.Text == "") ? "0" : Txt_DisposValue.Text)), Convert.ToDouble("0"), 0, "Null", Txt_Ref.Text, DateTime.Now, "none", DateTime.Now, 0);

               }
               else
               {
                   dis_sts = false;
               }

               if (Drp_method.SelectedIndex == 1)
               {
                   deplif = Convert.ToDouble((Txt_methdLife.Text == "") ? "0" : Txt_methdLife.Text);
                   meth = "STR";

                   double depamount = 0;

                   depamount = (Convert.ToDouble((Txt_PurCost.Text == "") ? "0" : Txt_PurCost.Text)) / (Convert.ToDouble((Txt_methdLife.Text == "") ? "0" : Txt_methdLife.Text));


                   double life1 = Convert.ToDouble((Txt_methdLife.Text == "") ? "0" : Txt_methdLife.Text);

                   int life = Convert.ToInt32(life1 * 12);
                   DateTime datejournal = Convert.ToDateTime(Txt_DTCP.Text).Date; ;





                   for (int i = 0; i < life; i++)
                   {
                       datejournal = Date_capt.AddMonths(i);
                       ProductProvider.Insert_JournalEntry(datejournal, "FIASS", Convert.ToInt32(ddlNominalAccount.SelectedValue), ddlLocations.SelectedValue, "Fixed Asset", Convert.ToInt32("0"), Convert.ToDouble("0"), depamount, 0, "Null", Txt_Ref.Text, DateTime.Now, "none", DateTime.Now, 0);
                       ProductProvider.Insert_JournalEntry(datejournal, "FIASS", Convert.ToInt32(ddlAccrunalNominalAC.SelectedValue), ddlLocations.SelectedValue, "Fixed Asset", Convert.ToInt32("0"), depamount, Convert.ToDouble("0"), 0, "Null", Txt_Ref.Text, DateTime.Now, "none", DateTime.Now, 0);

                   }





               }
               else if (Drp_method.SelectedIndex == 2)
               {

                   deprat = Convert.ToDouble((Txt_methodrate.Text == "") ? "0" : Txt_methodrate.Text);
                   meth = "RED";
               }

               ProductProvider.Insert_Fixed_Asset(Txt_Ref.Text, Txt_Desc.Text, Convert.ToInt32(ddlLocations.SelectedValue), Convert.ToInt32(ddlNominalAccount.SelectedValue), Convert.ToInt32(ddlAccrunalNominalAC.SelectedValue)
                   , Date_Pu, Date_capt, Convert.ToDouble(Txt_PurCost.Text), Convert.ToDouble(Txt_Qunty.Text), Date_exp, meth, deplif, deprat, dis_sts, Date_dis, 0, 0, (Convert.ToDouble((Txt_DisposValue.Text == "") ? "0" : Txt_DisposValue.Text)),fullname,fullname1,fullname2);




           }

         Response.Redirect("ShowAsset.aspx");



       }
       catch (Exception ex)
       {
           ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>alert('" + ex.Message + "');</script>", false);
       }


   }




and this is my

aspx code


ASP.NET
 <table>
 
   <tr>
 <td>Upload Document 1</td>
 <td>
     <asp:FileUpload ID="FileUpload1" runat="server" />
   </td>
    <td>
       <asp:LinkButton ID="LinkButton2" runat="server" onclick="LinkButton2_Click">
   </td>
  </tr>
 
 
 <tr>
 <td>Upload Image </td>
 <td>
  <asp:FileUpload ID="File_UP_Img" runat="server" />
   </td>
   <td>
       <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">
   </td>
  </tr>
  
 
 </table>
 
    
    
<table>
<tr>
<td>
    <asp:Button ID="Btn_Save" runat="server" Text="Save" onclick="Btn_Save_Click" 
        OnClientClick="return validatesave()" CausesValidation="False" />
</td>
</tr>

</table>
Posted
Updated 15-Nov-11 3:28am
v3
Comments
thatraja 15-Nov-11 9:23am    
where is the code? always include that in your question.

1 solution

Do you have any validation control assigned to file upload control?
Try by removing any validation controls.
 
Share this answer
 
Comments
dilip.aim11 15-Nov-11 9:01am    
i not assign any validation ....
i m checking only in javascript...

and is not necessary that user select file every time.....

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