如何将xxx.aspx页面上的js脚本调用xxx.aspx.cs中的方法
今天写js,做出了一个图片轮播图的效果,后来想把轮播图的图片能跟sql关联起来,只要新添加的图片就能自动在轮播图里显示,可是想了好久没做出来。因为不知道如何能把js里的代码跟xxx.aspx.cs里的方法关联。很纠结。页面中的关键代码大致如下:<div id="imgADPlayer"></div>
<script>
PImgPlayer.addItem( "白色恋人", "#", "images/banner1.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner2.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner3.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner4.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner5.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner6.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner7.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner8.jpg");
PImgPlayer.addItem( "白色恋人", "#", "images/banner9.jpg");
PImgPlayer.init( "imgADPlayer", 977, 304 );
</script><!--轮播图片--></div>
后台的sql语句如下:
select top(9) Pid,PName,PUrl,PImg from product order by Pid desc
xxx.aspx.cs中的方法如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
InitAddItem();
}
}
private void InitAddItem()
{
List<Products> list = (List<Products>)ProductsDAL.GetProForBanner();
for (int i = 0; i < 9; i++)
{
indexForm.Attributes.Add("onload","javascript:addItem("+list[i].PName+","+list[i].PUrl+","+list[i].PImg+")");
}
}
请问我该怎么做,是哪里写错了吗?还是我的思路不对呢?像高手请教