asp.net的服务器控件DropDownList的局部刷新,ASPX页面怎么接受不到返回值啊
aspx页面代码:<html><bodyonload="<%#loadMap()%>"><asp:ScriptManagerID="ScriptManager1"runa...
aspx页面代码:
<html>
<body onload="<%# loadMap()%>" >
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" EnableScriptGlobalization="True" EnableScriptLocalization="True" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color:#999999"> 第一步:</td>
<td> 请选择当前位置</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlVillage" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlVillage_SelectedIndexChanged">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td> </tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<body>
<html>
js代码:
<script type="text/javascript">
function initialize(LocalLon,LocalLat){
alert(LocalLon);
}
</script>
aspx.cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//获取省份
ProvinceCollection province = Province.GetProvinceOfChilds(-1);
//获取城市
ProvinceCollection city = Province.GetProvincesName();
//获取社区
CommunityCollection community = Community.GetCommunityName();
//下面三个方法分别是给省份,城市,小区下拉选择框添加数据的
GetProvince(province);
GetCity(city);
GetVillage(community);//显示小区列表
}
}
//省份发生改变时触发
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
//根据省份获取所属的城市
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
//根据城市获取所属的小区
}
//当更改小区时返回小区的坐标,
protected void ddlVillage_SelectedIndexChanged(object sender, EventArgs e)
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
loadMap();
}
decimal LocalLon =0;
decimal LocalLat =0;
public string loadMap()
{
string js = "initialize(" + LocalLon + "," + LocalLat + ")";
return js;
}
}
我想要问的是为什么我在aspx页面中不用UpdatePanel 就能获取到小区的坐标,用了UpdatePanel 就不能?一开始加载页面的时候可以弹出对话框,在改变小区值的时候就不弹出了,求高人指点啊
我要用后台代码返回从数据库里读取出来的值给页面的JS执行,并且在页面要实现局部刷新,现在用UpdatePanel 能实现局部刷新,可是后台代码返回不了值给js, 展开
<html>
<body onload="<%# loadMap()%>" >
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" EnableScriptGlobalization="True" EnableScriptLocalization="True" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="color:#999999"> 第一步:</td>
<td> 请选择当前位置</td>
<td>
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlVillage" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlVillage_SelectedIndexChanged">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td> </tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
<body>
<html>
js代码:
<script type="text/javascript">
function initialize(LocalLon,LocalLat){
alert(LocalLon);
}
</script>
aspx.cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//获取省份
ProvinceCollection province = Province.GetProvinceOfChilds(-1);
//获取城市
ProvinceCollection city = Province.GetProvincesName();
//获取社区
CommunityCollection community = Community.GetCommunityName();
//下面三个方法分别是给省份,城市,小区下拉选择框添加数据的
GetProvince(province);
GetCity(city);
GetVillage(community);//显示小区列表
}
}
//省份发生改变时触发
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
//根据省份获取所属的城市
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
//根据城市获取所属的小区
}
//当更改小区时返回小区的坐标,
protected void ddlVillage_SelectedIndexChanged(object sender, EventArgs e)
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
loadMap();
}
decimal LocalLon =0;
decimal LocalLat =0;
public string loadMap()
{
string js = "initialize(" + LocalLon + "," + LocalLat + ")";
return js;
}
}
我想要问的是为什么我在aspx页面中不用UpdatePanel 就能获取到小区的坐标,用了UpdatePanel 就不能?一开始加载页面的时候可以弹出对话框,在改变小区值的时候就不弹出了,求高人指点啊
我要用后台代码返回从数据库里读取出来的值给页面的JS执行,并且在页面要实现局部刷新,现在用UpdatePanel 能实现局部刷新,可是后台代码返回不了值给js, 展开
3个回答
展开全部
protected void ddlVillage_SelectedIndexChanged(object sender, EventArgs e)
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
loadMap();
}
修改为
protected void ddlVillage_SelectedIndexChanged(object sender, EventArgs e)
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "initialize(" + LocalLon + "," + LocalLat + ")", true);
}
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
loadMap();
}
修改为
protected void ddlVillage_SelectedIndexChanged(object sender, EventArgs e)
{
Village village = Village.GetVillageByCommunity(communityid);
LocalLon = village.VillageLon;
LocalLat = village.VillageLat;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "", "initialize(" + LocalLon + "," + LocalLat + ")", true);
}
追问
无法使用实例引用访问成员“System.Web.UI.ScriptManager.RegisterClientScriptBlock(System.Web.UI.Page, System.Type, string, string, bool)”;请改用类型名称对其加以限定
编译错误啊,而且我的没有RegisterClientScriptBlock()这个方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把<form id="xxx" runat="server"></form>这个标签加上
更多追问追答
追问
加了!没写出来,有字数限制的!还有很多代码没写出来
追答
你的页面enableviewstate有没有设为false?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把你项目的 有CSS 和图像的文件夹 删除,在重新新建下,在把文件复制进去,
这是因为 美工的编码和你项目中的文件夹编码不一致造成的
这是因为 美工的编码和你项目中的文件夹编码不一致造成的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询