-->

Friday, October 23, 2015

ASP.NET FILEUPLOAD CONTROL CHANGE BACKGROUND COLOR USING CODE

Each control in ASP.NET ToolBox 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 background color of ASP.NET file upload control.

Description
I explained, ASP.NET FILEUPLOAD CONTROL change border color, File upload control enable/disable

Source code




 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="fileupload_backcolor.aspx.cs" Inherits="fileupload_backcolor" %>  
 <!DOCTYPE html>  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
   <title></title>  
 </head>  
 <body>  
   <form id="form1" runat="server">  
   <div>  
     Enter Alpha color :  
     <asp:TextBox ID="TextBox1" runat="server" Width="202px"></asp:TextBox>  
     <br />  
     Enter Red Color :  
     <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 />  
   </div>  
     <asp:FileUpload ID="FileUpload1" runat="server" Height="51px" Width="311px" />  
   </form>  
 </body>  
 </html>  

Code Behind Code

 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.BackColor = System.Drawing.Color.FromArgb(alpha, red, green, blue);  
   }  
 }  

Code Generate the following output

programmatically change background color of fileupload control in ASP.NET

programmatically change background 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 and pass these values into the FromArgb ( ) method. This example is basically designed for users, who want to change the color of file upload control at run time.

Thursday, October 22, 2015

ASP.NET fileupload control change border color Programmatically

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="http://www.w3.org/1999/xhtml">  
 <head runat="server">  
   <title></title>  
 </head>  
 <body>  
   <form id="form1" runat="server">  
   <div>  
     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 />  
   </div>  
     <asp:FileUpload ID="FileUpload1" runat="server" Height="51px" Width="311px" />  
   </form>  
 </body>  
 </html>  


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.

ASP.NET FILEUPLOAD CONTROL INSERT IMAGE INTO DATABASE

Introduction

First of all, I would like to thank all of the readers who have read my previous articles. What a great support I have got from you people. By using ASP.NET File upload control, we can easily insert images into Table or you can say that we can create image gallery projects. With the help of JQuery, we put some dynamic effects like upload multiple files one by one. you can also do by JQuery to create button work as File upload. I really felt great when article Bind GridView was displayed on this blog page. Following are the articles that I have written so far for beginners as well as developers.



Follow some steps for inserting Images into database using asp.net fileupload control.

STEP-1 : Create Database Table

HOW TO INSERT IMAGE INTO DATABASE



STEP-2: Drag asp.net fileupload control from ToolBox and Drop it in Design window.


  <form id="form1" runat="server">  
   <div>  
     <asp:FileUpload ID="FileUpload1" runat="server" /><BR />  
     <asp:Button ID="Button1" runat="server" Text="Submit" />  
     <br />  
     <br />  
     <asp:Label ID="Result" runat="server"></asp:Label>  
   </div>  
   </form>  

fileuploadcontrol
STEP 3: Make a new directory in website folder name as "upload".
STEP 4:  Double click on submit button and raise click event.

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Web;  
 using System.Web.UI;  
 using System.Web.UI.WebControls;  
 using System.Data.SqlClient;  
 using System.Configuration;  
 using System.Data;  
 public partial class FILEUPLOAD : System.Web.UI.Page  
 {  
   protected void Page_Load(object sender, EventArgs e)  
   {  
   }  
   protected void Button1_Click(object sender, EventArgs e)  
   {  
     string imagedata = string.Empty;  
     if (FileUpload1.HasFile)  
     {  
       FileUpload1.SaveAs(Server.MapPath("~/upload/" + FileUpload1.FileName));  
       imagedata = "~/upload/" + FileUpload1.FileName;  
     }  
     using (SqlConnection con = new SqlConnection())  
     {  
       con.ConnectionString =ConfigurationManager .ConnectionStrings ["ConnectionString"].ToString ();  
       con.Open ();  
       using (SqlCommand cmd=new SqlCommand ())  
       {  
         cmd.Parameters.AddWithValue("@ur", imagedata);  
         cmd.CommandText ="insert into imagedata(url) values(@ur)";  
         cmd.Connection =con;  
         if (string.IsNullOrEmpty(imagedata))  
         {  
           Result.Text = "choose right image";  
         }  
         else  
         {  
           int a = cmd.ExecuteNonQuery();  
           if (a > 0)  
             Result.Text = "data inserted";  
           else  
             Result.Text = "failed";  
         }  
       }  
     }  
   }  
 }  

Output of the program
How to insert image into database using file upload control

How to insert image into database using file upload control
Here, first to insert images in website folder also get the File path during fileupload. Now, insert the file into Table as like Text. 
© Copyright 2013 Computer Programming | All Right Reserved