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