使用文件上传控件无法触发按钮单击事件 [英] button click event not firing with file upload control

查看:104
本文介绍了使用文件上传控件无法触发按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net页面中,我正在使用文件上传控件来上传文件...

但是当我选择任何文件并..点击保存按钮时......
然后我的按钮单击事件无法触发...

如果我在文件上传控件中未选择任何文件,则单击保存...

然后事件在触发...

我不明白问题出在哪里....

请帮助我.....

这是我的按钮点击代码...


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...


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);
       }


   }





这是我的

aspx代码






and this is my

aspx code


 <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>

推荐答案

您是否已将任何验证控件分配给文件上载控件?
尝试删除所有验证控件.
Do you have any validation control assigned to file upload control?
Try by removing any validation controls.


这篇关于使用文件上传控件无法触发按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆