Javascript webmethod中空洞函数的变换
我有一个函数,在加载页面时填充一个列表框(dispelitelist),它工作得很好Javascript webmethod中空洞函数的变换,javascript,c#,html,asp.net,webmethod,Javascript,C#,Html,Asp.net,Webmethod,我有一个函数,在加载页面时填充一个列表框(dispelitelist),它工作得很好 namespace DiveApp_WebApplication { public partial class HomePage : System.Web.UI.Page { private static DiveManager.DiveManager Manager; protected void Page_Load(object sender, EventAr
namespace DiveApp_WebApplication
{
public partial class HomePage : System.Web.UI.Page
{
private static DiveManager.DiveManager Manager;
protected void Page_Load(object sender, EventArgs e)
{
Manager = new DiveManager.DiveManager();
BindDiveList();
}
private void BindDiveList()
{
foreach (DiveSite DS in Manager.MasterDiveSiteList)
{
ListItem Item = new ListItem();
Item.Text = DS.DiveSiteName;
Item.Attributes.Add("Name", DS.DiveSiteName);
Item.Attributes.Add("Latitude", DS.Latitude.ToString().Replace(",", "."));
Item.Attributes.Add("Longitude", DS.Longitude.ToString().Replace(",","."));
Item.Attributes.Add("ID", DS.DiveSiteID.ToString());
Item.Attributes.Add("Vis", DS.AvarageVisibility.ToString());
Item.Attributes.Add("Depth", DS.MaximumDepth.ToString());
DiveSiteList.Items.Add(Item);
}
}
但现在我需要nuke并从JavaScript中重新填充该列表,我不知道如何操作。
我试过这样做,但它在DevisiteList(网页中的列表框)上说“非静态字段方法或属性需要对象引用”:
我尝试了一些不同的方法,但我有点迷路了,有人能帮我吗
编辑:主项目列表
public List<DiveSite> MasterDiveSiteList;
DiveDBClass = new DBAccessClass();
Initialize();
private void Initialize()
{
MasterDiveSiteList = DiveDBClass.GetAllDiveSites();
}
公共列表主列表;
DiveDBClass=新的DBAccessClass();
初始化();
私有void初始化()
{
MasterDiveSiteList=DiveDBClass.GetAllDiveSites();
}
第一次填充列表时,实例存在,因为它在页面上下文中执行
但是,当您通过JavaScript调用该方法时,您使用的是一个静态实例,该实例没有加载页面时的上下文
正确的方法是让JavaScript方法接收项目列表。然后可以在客户端填充它们
看看这个:
我们能看到MasterDevisiteList的实现吗?利希特:刚刚看到了,但那部分工作正常。。。我的问题是从javascript PageMethod访问BindDiveList()。我相信您遇到了此错误,因为DevisiteList实例存在于HomePage的执行上下文中。您的方法BindDiveListWeb()标记为静态。DevisiteList标记为静态吗?Juan:我去掉了static,但是现在,当我运行页面时,我得到了错误“UncaughtTypeError:PageMethods.BindDiveListWeb不是一个函数”
public List<DiveSite> MasterDiveSiteList;
DiveDBClass = new DBAccessClass();
Initialize();
private void Initialize()
{
MasterDiveSiteList = DiveDBClass.GetAllDiveSites();
}