Monday, April 28, 2008

How to Raise Events for FILEUPLOAD Control

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EventFileUpload.aspx.cs"
   Inherits="EventFileUpload" %>

<!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">

   <script type="text/javascript">
function GetFileName(val)
{
   var i = val.lastIndexOf("\\");
   return val.substring(i+1);
}
   </script>

   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
       <div>
           <asp:FileUpload ID="FileUpload1" runat="server" size="40"
onchange="this.form.TextBox1.value=GetFileName(this.value);" />
           <asp:TextBox ID="TextBox1" runat="server" />
       </div>
   </form>
</body>
</html>

3 comments :

  1. I had to change the text of a label and i set the innerHTML and it worked. :)


    function GetFileName(val)
    {
    debugger;
    var i = val.lastIndexOf("\\");
    document.getElementById('<%=lblFilePath.ClientID%>').innerHTML = val
    return true;
    }



    for,

    ReplyDelete
  2. Thank you so much!
    I've been looking for this for a very long time!

    ReplyDelete
  3. if the user is selected a file and click the cancel button of file upload popup...how we will handle the cancel event

    ReplyDelete