zoukankan      html  css  js  c++  java
  • 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;
    
               
    
     
    
            
    
     
    
     347px;
    
               
    
     
    
            
    
     
    
    top: 29px;
    
               
    
     
    
            
    
     
    
    left: 375px;
    
               
    
     
    
            
    
     
    
    position: absolute;
    
        }
    
           
    
     
    
    #form1
    
        {
    
               
    
     
    
            
    
     
    
    height: 783px;
    
        }
    
           
    
     
    
        
    
     
    
    img{max-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;  217px"/>
    
         
    
        
    
     
    
    <asp:ButtonID="Button1"runat="server"onclick="btnUpload_Click"
    
        
    
     
    
    Text="Upload"   style="top: 165px; left: 120px; position: absolute;  60px"/>
    
          
    
        
    
     
    
    </div>
    
     
    
        
    
        
    
     
    
    <divid="divImageSlider"class="flexslider"runat="server"         
    
     
    
        
    
     
    
    style="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:

    http://flexslider.woothemes.com/

  • 相关阅读:
    02
    springmvc根据请求uri获取handlermapping源码
    springmvc零xml配置原理
    maven使用tomcat插件出现Failed to start component [StandardService[Tomcat]]: Failed to start component [StandardEngine[Tomcat]]: A child container failed during startd错误
    zipkin以JAR文件启动以Mysql作为持久化方式
    OAuth2AuthenticationProcessingFilter资源认证服务器过滤器
    OAuth2中四种授权模式以及相应操作
    JVM双亲委派机制
    springcloud对应springboot版本【如果版本依赖不对,则会出现一堆神奇的问题】
    python实现一元二次表达式求值
  • 原文地址:https://www.cnblogs.com/happy-Chen/p/3680052.html
Copyright © 2011-2022 走看看