有一个aspx页面Default.aspx
一个javascript页面JScript.js
现在问题是一运行就提示找不到JScript.cs中的方法JS文件中的内容//注册一个称为Demo的新的命名空间
Type.registerNamespace("Demo");
/*
构造函数及私有变量声明
创建一个称为SlideShow的类
*/
Demo.SlideShow=function(){
this._slides=new Array();//包含图片URL地址
this._delay=2000;//播放间隔时间
this._currentIndex=0;//索引
this._pause=false;//运行或暂停
}
/*
原型定义部分
四个属性的getter/setter方法
*/
Demo.SlideShow.prototype={
get_Slides:function() {
return this._slides;
},
set_Slides:function(value) {
this._slides=value;
},
get_Delay:function() {
return this._delay;
},
set_Delay:function(value) {
this._delay=value;
},
get_CurrentIndex:function() {
return this._currentIndex;
},
set_CurrentIndex:function(value) {
if(value<0) {
this._currentIndex=this._slides.length-1;
return;
}
if(value>=this._slides.length) {
this._currentIndex=0;
}
else{
this._currentIndex=value;
}
},
get_IsPaused:function() {
return this._pause;
},
set_IsPaused:function(value) {
this.pause=value;
},
/*用来设置幻灯片的状态*/
Pause:function() {
this._pause=true;
},
Play:function() {
this._pause=false;/*设置为false后开始播放*/
window.setTimeout("slideshow.ShowImage()",this.get_Delay());
},
/*第一张*/
ShowFirst:function() {
this._currentIndex=0;
this.ShowImage();
},
/*最后一张*/
ShowLast:function() {
this._currentIndex=this._slides.length-1;
this.ShowImage();
},
/*下一张*/
ShowNext:function() {
var newIndex=this._currentIndex +1;
this.set_CurrentIndex(newIndex);
this.ShowImage();
},
/*调整值*/
ShowPrevious:function()
{
var newIndex=this._currentIndex -1;
this.set_CurrentIndex(newIndex);
this.ShowImage();
},
ShowImage: function () {
//$等价于等价于document.getElementById("")方法
var img=$get("Image1");
if(img.style.visibility=="hidden") {
img.style.visibility="visible";
}
var slides=this.get_Slides();
var curIndex=this.get_CurrentIndex();
img.src=slides[curIndex];
if(this.get_IsPaused()==false){
this.set_CurrentIndex(curIndex+1);
this.Play();
}
}
}/*方法SlideShow结束*/
/*注册到MS AJAX框架*/
Demo.SlideShow.registerClass("Demo.SlideShow");
//创建全局SlideShow类的实例
var slideshow=new Demo.SlideShow();后台代码 [WebMethod]
public static string[] GetSlides()
{
string[] slides = new string[4];
slides[0] = @"~\images\slide1.jpg";
slides[1] = @"~\images\slide2.jpg";
slides[2] = @"~\images\slide3.jpg";
slides[3] = @"~\images\slide4.jpg";
return slides;
}
另外我在ScriptManager中也把JS文件添加进集合了
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Scripts>
<asp:ScriptReference Path="~/JScript.js" />
</Scripts>
</asp:ScriptManager>
现在就是一运行就这么提示
错误 1 “ASP.default_aspx”不包含“slideshow”的定义,并且找不到可接受类型为“ASP.default_aspx”的第一个参数的扩展方法“slideshow”(是否缺少 using 指令或程序集引用?)
我不知道为什么找不到。求大神解决一下啦
一个javascript页面JScript.js
现在问题是一运行就提示找不到JScript.cs中的方法JS文件中的内容//注册一个称为Demo的新的命名空间
Type.registerNamespace("Demo");
/*
构造函数及私有变量声明
创建一个称为SlideShow的类
*/
Demo.SlideShow=function(){
this._slides=new Array();//包含图片URL地址
this._delay=2000;//播放间隔时间
this._currentIndex=0;//索引
this._pause=false;//运行或暂停
}
/*
原型定义部分
四个属性的getter/setter方法
*/
Demo.SlideShow.prototype={
get_Slides:function() {
return this._slides;
},
set_Slides:function(value) {
this._slides=value;
},
get_Delay:function() {
return this._delay;
},
set_Delay:function(value) {
this._delay=value;
},
get_CurrentIndex:function() {
return this._currentIndex;
},
set_CurrentIndex:function(value) {
if(value<0) {
this._currentIndex=this._slides.length-1;
return;
}
if(value>=this._slides.length) {
this._currentIndex=0;
}
else{
this._currentIndex=value;
}
},
get_IsPaused:function() {
return this._pause;
},
set_IsPaused:function(value) {
this.pause=value;
},
/*用来设置幻灯片的状态*/
Pause:function() {
this._pause=true;
},
Play:function() {
this._pause=false;/*设置为false后开始播放*/
window.setTimeout("slideshow.ShowImage()",this.get_Delay());
},
/*第一张*/
ShowFirst:function() {
this._currentIndex=0;
this.ShowImage();
},
/*最后一张*/
ShowLast:function() {
this._currentIndex=this._slides.length-1;
this.ShowImage();
},
/*下一张*/
ShowNext:function() {
var newIndex=this._currentIndex +1;
this.set_CurrentIndex(newIndex);
this.ShowImage();
},
/*调整值*/
ShowPrevious:function()
{
var newIndex=this._currentIndex -1;
this.set_CurrentIndex(newIndex);
this.ShowImage();
},
ShowImage: function () {
//$等价于等价于document.getElementById("")方法
var img=$get("Image1");
if(img.style.visibility=="hidden") {
img.style.visibility="visible";
}
var slides=this.get_Slides();
var curIndex=this.get_CurrentIndex();
img.src=slides[curIndex];
if(this.get_IsPaused()==false){
this.set_CurrentIndex(curIndex+1);
this.Play();
}
}
}/*方法SlideShow结束*/
/*注册到MS AJAX框架*/
Demo.SlideShow.registerClass("Demo.SlideShow");
//创建全局SlideShow类的实例
var slideshow=new Demo.SlideShow();后台代码 [WebMethod]
public static string[] GetSlides()
{
string[] slides = new string[4];
slides[0] = @"~\images\slide1.jpg";
slides[1] = @"~\images\slide2.jpg";
slides[2] = @"~\images\slide3.jpg";
slides[3] = @"~\images\slide4.jpg";
return slides;
}
另外我在ScriptManager中也把JS文件添加进集合了
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
<Scripts>
<asp:ScriptReference Path="~/JScript.js" />
</Scripts>
</asp:ScriptManager>
现在就是一运行就这么提示
错误 1 “ASP.default_aspx”不包含“slideshow”的定义,并且找不到可接受类型为“ASP.default_aspx”的第一个参数的扩展方法“slideshow”(是否缺少 using 指令或程序集引用?)
我不知道为什么找不到。求大神解决一下啦
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货