How to Raise Events for FILEUPLOAD Control

ASP.NET is an open-source, server-side web application framework designed for web development to produce dynamic web pages. Microsoft developed it to allow programmers to build active websites, applications and services. Wikipedia

This post will show you a straightforward trick to raise the event of ASP.NET file upload control. Check out the following code snippets; it is straightforward to understand

<%@ 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>

Post a Comment

Please do not post any spam link in the comment box😊

Previous Post Next Post

Blog ads

CodeGuru