从我的网站中的 aspx.cs 类访问变量! (ASP.NET Web 表单)
我的计划是从数据库访问航点并在 bing 地图中将它们显示为折线。 问题如下:我有我的default.aspx.cs类:
public partial class _Default : System.Web.UI.Page
{
List<Waypoints> waypointList;
IWaypointLogic waypointLogic;
protected void Page_Load(object sender, EventArgs e)
{
waypointLogic = new WaypointLogic();
waypointList = waypointLogic.GetWaypointsByTrackId(1);
}
}
现在我想访问我的default.aspx页面中的waypointList。 我想做类似的事情:
<% foreach (GPS_Tracker.Entities.Waypoints waypoint in waypointList %>
但我无法像这样访问 waypointList,可以吗?
My plan is to access waypoints from a database and show them in bing maps as a polyline.
The problem is the following: I have my default.aspx.cs class:
public partial class _Default : System.Web.UI.Page
{
List<Waypoints> waypointList;
IWaypointLogic waypointLogic;
protected void Page_Load(object sender, EventArgs e)
{
waypointLogic = new WaypointLogic();
waypointList = waypointLogic.GetWaypointsByTrackId(1);
}
}
And now I want to access the waypointList in my default.aspx page.
I want to do something like:
<% foreach (GPS_Tracker.Entities.Waypoints waypoint in waypointList %>
But I can't access the waypointList like this, can I?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将其设置为受保护,则可以访问它,因为 aspx 标记会生成一个继承您的代码的类。如果合适的话,还可以考虑使用一些数据绑定控件。
You can access it if you make it protected since the aspx markup generates a class that inherits your code behind. Also consider using some databound control if appropriate.
将您的字段范围更改为受保护。例如
Change the scope of your field to protected. e.g.
尝试将您的变量设为
public
。编辑:您也可以将它们设置为
protected
来访问它们,您可以参考乔治对我的答案的评论,以了解为什么应该使用protected
而不是公共
。try making your variables
public
.EDIT:Also you can make them
protected
to access them, you can refer to George's comment on my answer for an explanation why you should useprotected
instead ofpublic
.