Click here to Skip to main content
16,012,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Problem is i have a Button inside Update panel when i'm clicking it then it only showing Update progress gif but nothing happening but when i'm removing update panel then code it working Fine.But i want to use Update panel to perform this task anyone can help?thanks in advance.

here is my code-
ASP.NET
<div id ="shahid">
       <asp:ScriptManager ID="ScriptManager1" runat="server">
      </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
      
      <ContentTemplate>
<div id="rights">
<div id="my" style="margin-removed150px">
<span id="profile" style="margin-removed300px;color:Red;font-size:25px;font-family:Script MT Bold ">Change Picture</span>
<hr style="width:240px; size:5px; color:#2291FF"/>

      
    <asp:FileUpload ID="FileUpload1" runat="server" style="margin-left:230px;margin-top:50px" />
   <br /> <asp:Button ID="Button1" runat="server" Text="Change" 
        style="margin-left:230px;margin-top:10px" onclick="Button1_Click" /><br />
    <asp:Label ID="Label1" runat="server" style="margin-left:230px;margin-top:10px" ></asp:Label>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
    <ProgressTemplate>
    <img src="image/ajax.gif" />
    
    </ProgressTemplate>
    </asp:UpdateProgress>
    
                        </div>



  
</div>
<div id="left">


    <asp:Image ID="Image1" runat="server" Height="155px" Width="150px" />


    <div id="menuwrapper">
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Edit Profile</a>
                <ul>
                    <li><a href="#">Product 1</a>
                        <ul>
                            <li><a href="#">Sub Product 1</a></li>
                            <li><a href="#">Sub Product 2</a></li>
                            <li><a href="#">Sub Product 3</a></li>
                        </ul>
                    </li>
                    <li><a href="#">Product 2</a></li>
                    <li><a href="#">Product 3</a></li>
                </ul>
            </li>
            <li><a href="#">My Comments</a>
                <ul>
                    <li><a href="#">Faqs</a></li>
                    <li><a href="#">Contact Us</a></li>
                    <li><a href="#">Where are we?</a></li>
                </ul>
            </li>
            <li><a href="#">Setting</a>
        </li></ul>
    </div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>


and CS part is-
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Thread.Sleep(2000);

        string name = FileUpload1.FileName;
            string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
            //Label1.Text = name + " " + ext;
            if (FileUpload1.PostedFile.ContentLength == 0)
            {

                Label1.Text = "Can't upload zero length file";
                Label1.ForeColor = System.Drawing.Color.Red;
            }

            else
                if (ext == ".jpg" || ext == ".png" || ext == ".bmp")
                {
                    DateTime dt = DateTime.Now;
                    string tme = dt.ToLongTimeString();
                    string[] t = tme.Split(':');

                    string y = "";
                    foreach (string x in t)
                    {
                        y += x;
                    }

                    string aa = y + "_" + name;
                    string location = Server.MapPath("") + "\\Profilepic\\" + aa;
                    //string location2 = Server.MapPath("")+"\\images\\" + "\\" + DropDownList1.SelectedItem.Text + aa;


                    FileUpload1.PostedFile.SaveAs(location);
                    //Bitmap OriginalBM = new Bitmap(location);

                    //Size newSize = new Size(100, 100);
                    //Bitmap ResizedBM = new Bitmap(OriginalBM, newSize);

                    //ResizedBM.Save(location2, ImageFormat.Jpeg);
                    string loc = aa;

                    string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
                    SqlConnection Sqlconn = new SqlConnection(SqlConnect);
                    SqlCommand Sqlcomm = new SqlCommand("Update signup set dpurl='"+loc+"' where email='" + Session["email"].ToString() + "'", Sqlconn);
                    Sqlconn.Open();
                    Sqlcomm.ExecuteNonQuery();
                    Sqlconn.Close();
                    showpic();



                }



    }
    public void showpic()
    {


        string SqlConnect = System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString;
        SqlConnection Sqlconn = new SqlConnection(SqlConnect);
        SqlCommand sqlcomm = new SqlCommand("select * from signup where email='" + Session["email"].ToString() + "'", Sqlconn);
        Sqlconn.Open();
        SqlDataReader dr = sqlcomm.ExecuteReader();
        if (dr.Read())
        {

            Image1.ImageUrl = "Profilepic\\" + dr["dpurl"].ToString();


            dr.Close();
            Sqlconn.Close();

        }
    
    
    
    
    
    }
Posted
Comments
Er. Gayatri 26-Nov-12 4:19am    
You cannot use file upload control inside update panel. It requires full postback to upload a file using asp file Upload control.
Surendra0x2 28-Nov-12 12:33pm    
OOps :| thanks by d way :(
Surendra0x2 28-Nov-12 13:02pm    
it is possible gayatri mam
check this link ;)
http://www.aspsnippets.com/Articles/Using-FileUpload-Control-inside-ASP.Net-AJAX-UpdatePanel-Control.aspx
Surendra0x2 28-Nov-12 13:03pm    
it is called indian coding Jugaad :P Mudassar Sir did this :D
Surendra0x2 29-Nov-12 3:23am    
Ajax Asycfileupload control is an alternate solution for this problem :)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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