1 Replies - 1928 Views - Last Post: 12 September 2013 - 07:39 AM Rate Topic: -----

#1 CY5  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 350
  • Joined: 28-September 12

Problem in Ajax in Asp.net

Posted 12 September 2013 - 06:54 AM

I wanted to create a non-filckering of page while my image file is uploaded and displayed i.e using Ajax.

Please Look at my code,when i write runat="server" in <asp:UpdatePanel>, i am not able to upload my image.The Error "No File Found" is displayed, when i remove runat="server" iam able to upload my image file and display it , but this is simple a post back which can be done without ajax.Please help i wanted to use Ajax with File Upload

I have added ScriptManager in My Master Page


Default.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <link href="StyleSheet2.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:UpdatePanel Id="UpdatePanel1" runat="server" >
<ContentTemplate>
    <asp:Panel ID="Panel1" runat="server" Height="431px" Width="627px">
        <asp:Image ID="Image2" runat="server" Height="188px" Width="627px" />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <br /><br />
        <asp:Image ID="Image3" runat="server" Height="88px" Width="114px" />
        <br />
        <br />
        <asp:FileUpload ID="FileUpload1" runat="server" BorderStyle="Outset" />
        <br />
        
        <asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
   <asp:UpdateProgress ID="UpdateProgress1" runat="server">
      <ProgressTemplate>
      <div class="pq">
      Please Wait...
      </div>
      </ProgressTemplate>
      </asp:UpdateProgress>
  </asp:Panel>
    </ContentTemplate>
      </asp:UpdatePanel>
      
       
</asp:Content>



Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Drawing.Imaging;
using System.Diagnostics;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "";
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        if (FileUpload1.HasFile)
        {
            
                string strFileName = Path.GetFileName(FileUpload1.FileName);  //fileupload1 is the <asp:fileupload ID
                FileUpload1.SaveAs(Server.MapPath("~/" + strFileName));
                Image2.ImageUrl = "~/" + strFileName;
                Image3.ImageUrl = "~/" + strFileName; 
        }
        else
        {

            Label1.Text = "No file uploaded!";
        }
        System.Threading.Thread.Sleep(5000);
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Problem in Ajax in Asp.net

#2 CY5  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 350
  • Joined: 28-September 12

Re: Problem in Ajax in Asp.net

Posted 12 September 2013 - 07:39 AM

I got one answer of using Ajax Toolkit since
Regular FileUpload control doesnt play well with updatepanel....so either use -

http://www.asp.net/a...FileUpload.aspx

http://www.asp.net/a...FileUpload.aspx


But friends please suggest if you know other way.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1