ASP.NET fileupload control change border color Programmatically

October 22, 2015 , 0 Comments

Each control in tools of visual studio, treat as a class. Property window shows the behavior of their controls also contains some common property, such as back-color, border color etc. Now in this article, we will take a simple example to change the border color with border style of ASP.NET FILEUPLOAD control. I explained, How to use file upload, enable/disable file upload and many more properties.

Source code

 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileupload_backcolor.aspx.cs" Inherits="fileupload_backcolor" %>  
 <!DOCTYPE html>  
 <html xmlns="">  
 <head runat="server">  
   <form id="form1" runat="server">  
     Enter Alpha color :  
     <asp:TextBox ID="TextBox1" runat="server" Width="202px"></asp:TextBox>  
     <br />  
     Enter Red Color :&nbsp;&nbsp;  
     <asp:TextBox ID="TextBox2" runat="server" Width="202px"></asp:TextBox>  
     <br />  
     Enter Green Color:  
     <asp:TextBox ID="TextBox3" runat="server" Width="202px"></asp:TextBox>  
     <br />  
     Enter Blue Color&nbsp;&nbsp; :  
     <asp:TextBox ID="TextBox4" runat="server" Width="202px"></asp:TextBox>  
     <br />  
     <br />  
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Change Fileupload background color" Width="260px" />  
     <br />  
     <br />  
     <asp:FileUpload ID="FileUpload1" runat="server" Height="51px" Width="311px" />  

code behind

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 public partial class fileupload_backcolor : System.Web.UI.Page  
   protected void Page_Load(object sender, EventArgs e)  
   protected void Button1_Click(object sender, EventArgs e)  
     int alpha = int.Parse(TextBox1 .Text);  
     int red = int.Parse(TextBox2.Text);  
     int green = int.Parse(TextBox3.Text);  
     int blue = int.Parse(TextBox4.Text);  
     FileUpload1.BorderColor = System.Drawing.Color.FromArgb(alpha, red, green, blue);  
     FileUpload1.BorderStyle = BorderStyle.Solid;  
     FileUpload1.BorderWidth = 2;  

Code Generates the following output

Programmatically change border color of fileupload control in ASP.NET

Programmatically change border color of fileupload control in ASP.NET

In this example, we are taking four textboxes, one button, one file upload control. Using text box we can input the color code value, pass these values in the FromArgb ( ) method as an argument. This example is basically designed for users, who want to change the border color of ASP.NET FILEUPLOAD control at run time.

Bill Smithwick

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google