Sunday, 28 April 2013

ajax asyncfileupload textbox after file upload in asp.net


Design Code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
    <div>
 
    <table align="center">
    <tr><td>Upload</td><td>
        <asp:AsyncFileUpload ID="fileUpload1" runat="server" OnUploadedComplete="fileUploadComplete" /><br /><asp:Label ID="lb" runat="server"></asp:Label>
    </td></tr>
    <tr><td><asp:CheckBox ID="cb" runat="server" AutoPostBack="true"
            oncheckedchanged="cb_CheckedChanged" />Press Me</td><td>
      <asp:Button  ID="btn" runat="server" Text="Save" onclick="btn_Click" />
    </td></tr>
    </table>
  
    </div>
    </form>
</body>
</html>
C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Click(object sender, EventArgs e)
    {
        lb.Text = Application["x"].ToString();
    }
    protected void fileUploadComplete(object sender, AsyncFileUploadEventArgs e)
    {
       Thread.Sleep(1000);
        string filename = System.IO.Path.GetFileName(fileUpload1.FileName);
        Application["x"] = filename;
        fileUpload1.SaveAs(Server.MapPath("image/") + filename);
      
     

    }

    protected void cb_CheckedChanged(object sender, EventArgs e)
    {
       
    }
}

No comments:

Post a Comment