本文介绍了ASP.NET网站中的加载图像滑块问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个团体

i在asp.net网站项目中加载图片滑块有问题,我想运行动态滑块但不能正常工作。

这是下面的aspx文件:


<%@ Master Language =C#AutoEventWireup =trueCodeFile =MasterPageTest.master.csInherits =MasterPageTest %>











< title>

< asp:contentplaceholder id =headrunat =server>











$(document).ready(function(){

InitializeImageSlider( );

});

函数InitializeImageSlider(){

$('。flexslider')。flexslider({

动画:幻灯片,

controlNav:true,

directionNav:true,

itemWidth: 100%,

itemHeight:400

});

}





.error,.notice,.success

{

填充:.8em;

margin-bottom :1em;

border:2px solid #ddd;

}

.error

{

背景:#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 =服务器visible =false>

< asp:fileupload id =fluImagerunat =servervisible =false>

 

< asp:button id =btn_Uploadrunat =servertext =Uploadonclick =btnUploadvisible =fa lse>

 

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







< asp:contentplaceholder id =ContentPlaceHolder1runat =服务器>









cs文件:

使用System;

使用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发件人,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(文件信息在rgFiles中)

    {

    fileSlide = @
  • ;



    divSlider + = fileSlide;

    }



    divImageSlider.InnerHtml = divSlider +
;



}

catch(例外情况)

{

// 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 image slider
but does not work please help .thank you so much

解决方案



这篇关于ASP.NET网站中的加载图像滑块问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 21:36