Click here to Skip to main content
15,903,523 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an image button and i want to upload an file on cimage click.

my image button and uploader markup is
CSS
<asp:FileUpload ID="fplUploadExcel" runat="server" Style="position: relative; visibility: hidden;
                height: 20px;" ClientIDMode="Static" />


CSS
<asp:ImageButton ID="ImageButton1" runat="server" Width="150px" Style="position: relative;"
                ImageUrl="~/Images/Uploadingimage.jpg" />



And i m getting click of uploader as follws on page load is

ImageButton1.Attributes["onclick"] = string.Format("document.getElementById('{0}').click();", fplUploadExcel.ClientID);

but don't hoe to call the upload function please tell me how will i do this

my upload function is
C#
protected void uploadExcel()
    {
        

        if (fplUploadExcel.HasFile)
        {
            // string excelfilepath = fplUploadExcel.PostedFile.FileName;
            //if (fplUploadExcel.PostedFile.FileName == "EmployeeSheet.xlsx")
            //{
            string filename = Server.MapPath(@"~\\Excel\\");
            fplUploadExcel.PostedFile.SaveAs(filename + fplUploadExcel.FileName);

            
            string excelfilepath = Server.MapPath("~\\Excel\\" + fplUploadExcel.FileName);

            importdatafromexcel(excelfilepath);

            SelectUpdaterecordFeromExcel();
Posted

1 solution

I got your problem if you want to call a serverside function you need to use onclick and if you want to use clientside function use "onclientclick"

pls try this for your requirement

CSS
<asp:ImageButton ID="ImageButton1" runat="server" Width="150px" Style="position: relative;"ImageUrl="~/Images/Uploadingimage.jpg" onclick="uploadExcel()"/>


And replace your form tag with this
<form id="form1" enctype="multipart/form-data" runat="server">

All the best:)
 
Share this answer
 
v2
Comments
ajays3356 25-Jan-14 3:42am    
i had tried this way but this function if(fplUploadexcel.hasfile) shows false and control passes to to else part.
karthik Udhayakumar 25-Jan-14 3:55am    
Are you using a Update panel?
karthik Udhayakumar 25-Jan-14 3:57am    
Replace this with your form tag
<form id="form1" enctype="multipart/form-data" runat="server"> and let me know

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