asp.net 为什么用了ajax,页面还是刷新? 30
aspx:<div><asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:DropD...
aspx:
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
<br /><br />
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
<br /><br />
<asp:DropDownList ID="ddlRegion" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
provinceData();
ddlProvince.Items.Insert(0,new ListItem("=请选择省份=","0"));
ddlCity.Items.Insert(0, new ListItem("=请选择城市=","0"));
ddlRegion.Items.Insert(0, new ListItem("=请选择区县=","0"));
}
}
private void provinceData()
{
ixiniu.BLL.province provinceBLL = new ixiniu.BLL.province();
ddlProvince.DataSource = provinceBLL.GetAllList();
ddlProvince.DataValueField = "id";
ddlProvince.DataTextField = "p_name";
ddlProvince.DataBind();
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
ixiniu.BLL.city cityBLL = new BLL.city();
ddlCity.DataSource = cityBLL.GetList(string.Format("p_id={0}", ddlProvince.SelectedValue));
ddlCity.DataValueField = "id";
ddlCity.DataTextField = "c_name";
ddlCity.DataBind();
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
ixiniu.BLL.region regionBLL = new BLL.region();
ddlRegion.DataSource = regionBLL.GetList(string.Format("c_id={0}", ddlCity.SelectedValue));
ddlRegion.DataValueField = "id";
ddlRegion.DataTextField = "r_name";
ddlRegion.DataBind();
} 展开
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
<br /><br />
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
<br /><br />
<asp:DropDownList ID="ddlRegion" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
provinceData();
ddlProvince.Items.Insert(0,new ListItem("=请选择省份=","0"));
ddlCity.Items.Insert(0, new ListItem("=请选择城市=","0"));
ddlRegion.Items.Insert(0, new ListItem("=请选择区县=","0"));
}
}
private void provinceData()
{
ixiniu.BLL.province provinceBLL = new ixiniu.BLL.province();
ddlProvince.DataSource = provinceBLL.GetAllList();
ddlProvince.DataValueField = "id";
ddlProvince.DataTextField = "p_name";
ddlProvince.DataBind();
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
ixiniu.BLL.city cityBLL = new BLL.city();
ddlCity.DataSource = cityBLL.GetList(string.Format("p_id={0}", ddlProvince.SelectedValue));
ddlCity.DataValueField = "id";
ddlCity.DataTextField = "c_name";
ddlCity.DataBind();
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
ixiniu.BLL.region regionBLL = new BLL.region();
ddlRegion.DataSource = regionBLL.GetList(string.Format("c_id={0}", ddlCity.SelectedValue));
ddlRegion.DataValueField = "id";
ddlRegion.DataTextField = "r_name";
ddlRegion.DataBind();
} 展开
5个回答
展开全部
你确定整个页面Postback了?
我把你带吗直接复制过来 没有出现整个页面PostBack的.
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="btnt" Text="按钮" runat="server" onclick="btnt_Click" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="ddlRegion" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlProvince.Items.Add(new ListItem("省份1"));
ddlProvince.Items.Add(new ListItem("省份2"));
ddlProvince.Items.Add(new ListItem("省份3"));
}
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.Items.Add(new ListItem("城市1"));
ddlCity.Items.Add(new ListItem("城市2"));
ddlCity.Items.Add(new ListItem("城市3"));
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
ddlRegion.Items.Add(new ListItem("片区1"));
ddlRegion.Items.Add(new ListItem("片区2"));
ddlRegion.Items.Add(new ListItem("片区3"));
}
protected void btnt_Click(object sender, EventArgs e)
{
Label1.Text = "未刷新";
}
我把你带吗直接复制过来 没有出现整个页面PostBack的.
<form id="form1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="btnt" Text="按钮" runat="server" onclick="btnt_Click" />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged">
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="ddlCity" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged">
</asp:DropDownList>
<br />
<br />
<asp:DropDownList ID="ddlRegion" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ddlProvince.Items.Add(new ListItem("省份1"));
ddlProvince.Items.Add(new ListItem("省份2"));
ddlProvince.Items.Add(new ListItem("省份3"));
}
}
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
ddlCity.Items.Add(new ListItem("城市1"));
ddlCity.Items.Add(new ListItem("城市2"));
ddlCity.Items.Add(new ListItem("城市3"));
}
protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
ddlRegion.Items.Add(new ListItem("片区1"));
ddlRegion.Items.Add(new ListItem("片区2"));
ddlRegion.Items.Add(new ListItem("片区3"));
}
protected void btnt_Click(object sender, EventArgs e)
{
Label1.Text = "未刷新";
}
更多追问追答
追问
在div的前面加上一串,选择下拉列表后,会回到顶部
追答
额, 明白你说的意思了, 但是你的页面的确没有整个页面Postback
用UpdatePanel 如果页面结构比较复杂 是会出现这样奇怪的问题,
我们之前的解决方案 是抛弃了 UpdatePanel
完全用 Ajax + httpHandler 解决这样布局错位的问题.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的代码我用了,就你贴出的这部分代码是没有问题的,如果你还是发现不了问题,建议你从新建立一个页面把这段代码copy过去,兴许问题就解决了
更多追问追答
追问
没用
追答
如果可以的话,你把你整个应用程序的解决方案发给我,兴许还能帮你看看,至少你这段代码是没问题的,看不出问题来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
奇怪的是,既然用UpdatePanel,为什么没有ScriptMananger呢。。。。
追问
输入字符数有限制,我都用ajax控件了,我还不知道加个ScriptMananger?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在页面里面加个ScriptManager,至于为什么,自己百度吧!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我也遇到了,可是现在我没有搜到why?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询