how to enable fileupload and button control after once uploading of images
<% @PageLanguage="C#"AutoEventWireup="true"CodeFile="FileuploadandButton.aspx.cs"Inherits="DataControl_FileuploadandButton" %> <! DOCTYPEhtml> < htmlxmlns="http://www.w3.org/1999/xhtml"> < headid="Head1"runat="server"> < title></title> <linkhref="../Scripts/flexslider.css"rel="stylesheet"/> <scriptsrc="../Scripts/jquery-1.7.1.min.js"></script> <scriptsrc="../Scripts/jquery.flexslider.js"></script> < scripttype="text/javascript"> $(document).ready( function () { InitializeImageSlider(); }); function InitializeImageSlider() { $( '.flexslider').flexslider({ animation: "slide", controlNav: false, directionNav: false, itemWidth: "120%", itemHeight: "50px", slideshowSpeed: 2000, }); } </script> <styletype="text/css"> #divMessage { height: 205px; width: 347px; top: 29px; left: 375px; position: absolute; } #form1 { height: 783px; } img{max-width:100%; height:400px; display: block;} .style1 { left: 448px; top: 23px; } </style> </head> <body> <formid="form1"runat="server"> <divstyle="height: 783px; background-color: #FFFFCC;"> <divid="divMessage"runat="server"align="center"class="style1"> <asp:FileUploadID="FileUpload2" runat="server" style="top: 95px; left: 86px; position: absolute; height: 22px; width: 217px"/> <asp:ButtonID="Button1"runat="server"onclick="btnUpload_Click" Text="Upload" style="top: 165px; left: 120px; position: absolute; width: 60px"/> </div> <divid="divImageSlider"class="flexslider"runat="server" style="width:343px; height:210px; top: 22px; left: 14px; position: absolute; margin-right: 7px;" align="right"> </div> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class DataControl_FileuploadandButton : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { LoadImage(); } } private void LoadImage() { try { string imagePath = "~/BannerImage/"; string imageSource = SiteBaseUrl + "/BannerImage/"; string PhotoFilePath = Server.MapPath(imagePath); string divSlider = @"<ul class='slides'>"; string fileSlide = string.Empty; string fileName = string.Empty; DirectoryInfo di = new DirectoryInfo(PhotoFilePath); FileInfo[] rgFiles = di.GetFiles("*.*"); foreach (FileInfo fi in rgFiles) { fileSlide =@"<li><img src='"; fileSlide += imageSource + fi +"' /></li>"; divSlider += fileSlide; } divImageSlider.InnerHtml = divSlider +"</ul>"; } catch (Exception ex) { } } public static string SiteBaseUrl { get { string orginalUrl = HttpContext.Current.Request.Url.AbsoluteUri; if (HttpContext.Current.Request.Url.Query.Length > 0) orginalUrl = orginalUrl.Replace(HttpContext.Current.Request.Url.Query, string.Empty); return orginalUrl.Replace(HttpContext.Current.Request.Url.AbsolutePath, string.Empty) + (( HttpContext.Current.Request.ApplicationPath == "/" ?"" : HttpContext.Current.Request.ApplicationPath)) + '/'; } } public void UploadImage() { if (CheckValidImage(FileUpload2)) { FileUpload2.PostedFile.SaveAs(MapPath("~") + "/BannerImage/" + FileUpload2.FileName); ShowErrorMsg("success", "Image Uploaded Successfully"); LoadImage(); } } private bool CheckValidImage(FileUpload FileUploadImage) { string contentType; contentType = FileUploadImage.PostedFile.ContentType.ToLower(); if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg") { } else { ShowErrorMsg("error", "Image format is not valid. Valid image formats are ( jpg, png, jpeg)."); return false; } return true; } private void ShowErrorMsg(string _class, string _msg) { divMessage.Style.Value = "display:block;"; divMessage.Attributes.Add("class", _class); // divMessage.Attributes.Add("display", "block"); //divMessage.InnerHtml = _msg; Label test=new Label(); test.Text=_msg; divMessage.Controls.Add(test); } protected void btnsave_Click(object sender, EventArgs e) { } protected void btnUpload_Click(object sender, EventArgs e) { UploadImage(); } }
FROM: