且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET网站中的加载图像滑块问题

更新时间:2023-01-24 15:37:21

(document).ready(function(){

InitializeImageSlider();

});

函数InitializeImageSlider(){


('。flexslider')。flexslider({

动画:slide,

controlNav:true,

directionNav:true,

itemWidth:100%,

itemHeight:400

});

}





。错误,.notice,.success

{

填充:.8em;

margin-bottom:1em;

border:2px solid #ddd;

}

.error

{

backg圆形:#FBE3E4;

颜色:#8a1f11;

border-color:#FBC2C4;

}

.notice

{

背景:#FFF6BF;

颜色:#514721;

border-color:# FFD324;

}

.success

{

背景:#E6EFC2;

颜色:#264409;

border-color:#C6D880;

}

.error a

{

颜色:#8a1f11;

}

。通知a

{

颜色:#514721;

}

。成功一个

{

颜色:#264409;

}









< asp: panel id =sliderPanelrunat =server>















< asp:label text =上传图片(.jpeg / .jpg / .png)runat =servervisible =false>

&lt ; asp:fileupload id =fluImagerunat =servervisible =false>

 

< asp:button id =btn_Uploadrunat =servertext =Uploadonclick =btnUploadvisible =false>

 

< asp:button id =Button2runat =servertext =刷新页面visible =false>







< asp:contentplaceholder id =ContentPlaceHolder1runat =server>









cs文件:

使用系统;

usin g System.Collections.Generic;

使用System.IO;

使用System.Linq;

使用System.Web;

使用System.Web.UI;

使用System.Web.UI.WebControls;



公共部分类MasterPageTest:System .Web.UI.MasterPage

{

protected void Page_Load(object sender,EventArgs e)

{

LoadImage();

}



private void LoadImage()

{

尝试

{

string imagePath =〜/ Upload / BannerImage /;

string imageSource = SiteBaseUrl +Upload / BannerImage / ; $ / b $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ string fileSlide = string.Empty;

string fileName = string.Empty;



DirectoryInfo di = new Direc toryInfo(PhotoFilePath);

FileInfo [] rgFiles = di.GetFiles(*。*);

foreach(文件信息在rgFiles中)

{

fileSlide = @

  • ;



    divSlider + = fileSlide;

    }



    divImageSlider.InnerHtml = divSlider +;



    }

    catch(exception ex)

    {

    // ShowErrorMsg(error,ex.Message);

    }

    }



    公共静态字符串SiteBaseUrl

    {

    get

    {

    //返回ConfigurationManager.AppSettings [RootPath]。ToString();

    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))+'/';

    }



    }



    protected void btnUpload(object sender,EventArgs e)

    {

    if(CheckValidImage(fluImage))

    {

    fluImage.PostedFile.SaveAs(MapPath(〜)+ / Upload / BannerImage /+ fluImage.FileName);

    ShowErrorMsg(成功,آپلودعکسباموفقیتانجامشد...);

    }

    }



    private bool CheckValidImage(FileUpload FileUploadImage)

    {

    string contentType;



    contentType = FileUploadImage.PostedFile.ContentType.ToLower();



    if(contentType ==image / jpg|| contentType ==image / png|| contentType ==image / jpeg|| contentType ==image / pjpeg)

    {



    }

    else

    {

    ShowErrorMsg(error,فرمتیافالبعکسانتخابشدهصحیحنیست。(jpg,png,jpeg)لطفاازپسوندهایروبرواستفادهکنید。);



    返回false;

    }



    返回true;

    } $ / $
    private void ShowErrorMsg(string _class,string _msg)

    {

    divMessage.Style.Value =display:block;;

    divMessage.Attributes.Add(class,_ class);

    divMessage.InnerHtml = _msg;

    }

    }



    然后我创建一个包含母版页面的页面并运行..但是不起作用



    此代码在没有母版页的情况下运行良好。主要问题是母版页...



    我尝试过:


    运行动态图像滑块

    但不起作用请帮助。谢谢你这么多

    hi every body
    i have a problem with loading image slider in asp.net web site project that is i want to run a dynamic slider but does not work properly.
    this is aspx file below:

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPageTest.master.cs" Inherits="MasterPageTest" %>





    <title>
    <asp:contentplaceholder id="head" runat="server">





    $(document).ready(function () {
    InitializeImageSlider();
    });
    function InitializeImageSlider() {
    $('.flexslider').flexslider({
    animation: "slide",
    controlNav: true,
    directionNav: true,
    itemWidth: "100%",
    itemHeight: 400
    });
    }


    .error, .notice, .success
    {
    padding: .8em;
    margin-bottom: 1em;
    border: 2px solid #ddd;
    }
    .error
    {
    background: #FBE3E4;
    color: #8a1f11;
    border-color: #FBC2C4;
    }
    .notice
    {
    background: #FFF6BF;
    color: #514721;
    border-color: #FFD324;
    }
    .success
    {
    background: #E6EFC2;
    color: #264409;
    border-color: #C6D880;
    }
    .error a
    {
    color: #8a1f11;
    }
    .notice a
    {
    color: #514721;
    }
    .success a
    {
    color: #264409;
    }




    <asp:panel id="sliderPanel" runat="server">





    <asp:label text="Upload Image (.jpeg/.jpg/.png)" runat="server" visible="false">
    <asp:fileupload id="fluImage" runat="server" visible="false">
     
    <asp:button id="btn_Upload" runat="server" text="Upload" onclick="btnUpload" visible="false">
     
    <asp:button id="Button2" runat="server" text="Refresh Page" visible="false">




    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">




    cs file:
    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 MasterPageTest : System.Web.UI.MasterPage
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    LoadImage();
    }

    private void LoadImage()
    {
    try
    {
    string imagePath = "~/Upload/BannerImage/";
    string imageSource = SiteBaseUrl + "Upload/BannerImage/";
    string PhotoFilePath = Server.MapPath(imagePath);
    string divSlider = @"

      ";
      string fileSlide = string.Empty;
      string fileName = string.Empty;

      DirectoryInfo di = new DirectoryInfo(PhotoFilePath);
      FileInfo[] rgFiles = di.GetFiles("*.*");
      foreach (FileInfo fi in rgFiles)
      {
      fileSlide = @"
    • ";

      divSlider += fileSlide;
      }

      divImageSlider.InnerHtml = divSlider + "
    ";

    }
    catch (Exception ex)
    {
    //ShowErrorMsg("error", ex.Message);
    }
    }

    public static string SiteBaseUrl
    {
    get
    {
    //return ConfigurationManager.AppSettings["RootPath"].ToString();
    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)) + '/';
    }

    }

    protected void btnUpload(object sender, EventArgs e)
    {
    if (CheckValidImage(fluImage))
    {
    fluImage.PostedFile.SaveAs(MapPath("~") + "/Upload/BannerImage/" + fluImage.FileName);
    ShowErrorMsg("success", "آپلود عکس با موفقیت انجام شد...");
    }
    }

    private bool CheckValidImage(FileUpload FileUploadImage)
    {
    string contentType;

    contentType = FileUploadImage.PostedFile.ContentType.ToLower();

    if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg" || contentType == "image/pjpeg")
    {

    }
    else
    {
    ShowErrorMsg("error", "فرمت یا فالب عکس انتخاب شده صحیح نیست. ( 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.InnerHtml = _msg;
    }
    }

    and after that i create a page with master page and run..but does not work

    this code work well without master page.the main problem is master page...

    What I have tried:

    run a dynamic image slider
    but does not work please help .thank you so much

    (document).ready(function () {
    InitializeImageSlider();
    });
    function InitializeImageSlider() {


    ('.flexslider').flexslider({
    animation: "slide",
    controlNav: true,
    directionNav: true,
    itemWidth: "100%",
    itemHeight: 400
    });
    }


    .error, .notice, .success
    {
    padding: .8em;
    margin-bottom: 1em;
    border: 2px solid #ddd;
    }
    .error
    {
    background: #FBE3E4;
    color: #8a1f11;
    border-color: #FBC2C4;
    }
    .notice
    {
    background: #FFF6BF;
    color: #514721;
    border-color: #FFD324;
    }
    .success
    {
    background: #E6EFC2;
    color: #264409;
    border-color: #C6D880;
    }
    .error a
    {
    color: #8a1f11;
    }
    .notice a
    {
    color: #514721;
    }
    .success a
    {
    color: #264409;
    }




    <asp:panel id="sliderPanel" runat="server">





    <asp:label text="Upload Image (.jpeg/.jpg/.png)" runat="server" visible="false">
    <asp:fileupload id="fluImage" runat="server" visible="false">
     
    <asp:button id="btn_Upload" runat="server" text="Upload" onclick="btnUpload" visible="false">
     
    <asp:button id="Button2" runat="server" text="Refresh Page" visible="false">




    <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">




    cs file:
    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 MasterPageTest : System.Web.UI.MasterPage
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    LoadImage();
    }

    private void LoadImage()
    {
    try
    {
    string imagePath = "~/Upload/BannerImage/";
    string imageSource = SiteBaseUrl + "Upload/BannerImage/";
    string PhotoFilePath = Server.MapPath(imagePath);
    string divSlider = @"

      ";
      string fileSlide = string.Empty;
      string fileName = string.Empty;

      DirectoryInfo di = new DirectoryInfo(PhotoFilePath);
      FileInfo[] rgFiles = di.GetFiles("*.*");
      foreach (FileInfo fi in rgFiles)
      {
      fileSlide = @"
    • ";

      divSlider += fileSlide;
      }

      divImageSlider.InnerHtml = divSlider + "
    ";

    }
    catch (Exception ex)
    {
    //ShowErrorMsg("error", ex.Message);
    }
    }

    public static string SiteBaseUrl
    {
    get
    {
    //return ConfigurationManager.AppSettings["RootPath"].ToString();
    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)) + '/';
    }

    }

    protected void btnUpload(object sender, EventArgs e)
    {
    if (CheckValidImage(fluImage))
    {
    fluImage.PostedFile.SaveAs(MapPath("~") + "/Upload/BannerImage/" + fluImage.FileName);
    ShowErrorMsg("success", "آپلود عکس با موفقیت انجام شد...");
    }
    }

    private bool CheckValidImage(FileUpload FileUploadImage)
    {
    string contentType;

    contentType = FileUploadImage.PostedFile.ContentType.ToLower();

    if (contentType == "image/jpg" || contentType == "image/png" || contentType == "image/jpeg" || contentType == "image/pjpeg")
    {

    }
    else
    {
    ShowErrorMsg("error", "فرمت یا فالب عکس انتخاب شده صحیح نیست. ( 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.InnerHtml = _msg;
    }
    }

    and after that i create a page with master page and run..but does not work

    this code work well without master page.the main problem is master page...

    What I have tried:

    run a dynamic image slider
    but does not work please help .thank you so much