如何只让用户控件回传 用户控件内部动态添加了若干dropdownlist,同时订阅了它的SelectedIndexChange事件,由于必须要页面回传才会触发,有没有办法只让用户控件自身回传,而所在页面不回传? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 UpdatePanel可以实现既然不会传,直接使用ajax做东西更省事 我已经把用户控件放到UpdatePanel中了,可是还是回传。 我已经把用户控件放到UpdatePanel中了,可是还是回传。应该是没有用对吧UpdatePanel就是用来干这个的 <asp:ScriptManager ID="ScriptManager1" runat="server" > </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" RenderMode="Block"> <ContentTemplate> <uc1:MyControl ID="MyControl1" runat="server" /> </ContentTemplate> </asp:UpdatePanel>会不会是我在后台设置了dropdownlist的onchage属性,让它dopostback了,我的本意只想让用户控件回传。这样会使页面强制回传吗 以前贴过的一个demo<%@ Page Language="C#" %><script runat="server"> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.Calendar1.Style["position"] = "absolute"; this.TextBox1.DataBind(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { this.DropDownList2.Items.Clear(); switch (this.DropDownList1.SelectedValue) { case "北京": this.DropDownList2.Items.Add("天安门广场"); this.DropDownList2.Items.Add("颐和园"); this.DropDownList2.Items.Add("雍和宫"); this.DropDownList2.Items.Add("红螺寺"); break; case "上海": this.DropDownList2.Items.Add("崇明岛"); this.DropDownList2.Items.Add("外滩"); this.DropDownList2.Items.Add("万佛阁"); break; case "香港": this.DropDownList2.Items.Add("海洋公园"); this.DropDownList2.Items.Add("半岛酒店"); break; } } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { ShowResult(); } protected void Button1_Click(object sender, EventArgs e) { if (this.Calendar1.Visible) SetupTheDate(); else { try { this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text); this.Calendar1.VisibleDate = this.Calendar1.SelectedDate; } catch { } this.Calendar1.Visible = true; } } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { SetupTheDate(); } private void SetupTheDate() { this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString(); this.Calendar1.Visible = false; ShowResult(); } void ShowResult() { this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue; UpdatePanel3.Update(); }</script><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>演示使用基本的asp.net ajax功能</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>--请选择--</asp:ListItem> <asp:ListItem>北京</asp:ListItem> <asp:ListItem>上海</asp:ListItem> <asp:ListItem>香港</asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" /> </ContentTemplate> </asp:UpdatePanel> <br /> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> 请输入日期: </td> <td> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <table cellpadding="0" cellspacing="0"> <tr> <td> <asp:TextBox ID="TextBox1" runat="server" Width="147px" Text="<%# DateTime.Now.AddDays(20).ToShortDateString() %>" /> <asp:Button ID="Button1" runat="server" Text="..." OnClick="Button1_Click" /> </td> </tr> <tr> <td> <asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged" BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px"> <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" /> <SelectorStyle BackColor="#FFCC66" /> <TodayDayStyle BackColor="#FFCC66" ForeColor="White" /> <OtherMonthDayStyle ForeColor="#CC9966" /> <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" /> <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" /> <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" /> </asp:Calendar> </td> </tr> </table> </ContentTemplate> </asp:UpdatePanel> </td> </tr> </table> <hr /> <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional"> <ContentTemplate> result: <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Size="Small"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </form></body></html>要注意细节,认真学习细节。要知道UpdatePanel也是回发整个页面的,因此它是重量级的、很慢的。不过它没有全部——仅仅局部——刷新html/dom而已。这与轻量级的ajax是不同的。对于轻量级的ajax,那么asp.net ajax架构仅仅支持在ScriptManager中声明调用asmx这一种通讯方式,它并不支持把原来的asp.net服务器控件在ajax上实现,因此asp.net ajax基本上对轻量级ajax编程仅有通讯作用,对web2.0的GUI编程则豪没有意义。 gridview中修改的问题 发送文件的问题 sql 2005 的问题 数据库备份文件(居然是exe格式的)恢复问题 如何使用javascript获取gridview中子控件的数值呢? application/vnd.ms-excel方式输出,Excel打不开阿? 在C#中如何判断一个数值是否数字型?在asp中是用IsNumerice,但在C#中不了解 怎样学好.NET ====100分求一个取字符串的问题,请CSDN的朋友帮帮我,解决立即结帖===== 用“权限设计”的源码换取问题的答案 网页显示pdf出错 access denied 关于数据横向显示的问题
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" RenderMode="Block">
<ContentTemplate> <uc1:MyControl ID="MyControl1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
会不会是我在后台设置了dropdownlist的onchage属性,让它dopostback了,我的本意只想让用户控件回传。这样会使页面强制回传吗
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.Calendar1.Style["position"] = "absolute";
this.TextBox1.DataBind();
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.DropDownList2.Items.Clear();
switch (this.DropDownList1.SelectedValue)
{
case "北京":
this.DropDownList2.Items.Add("天安门广场");
this.DropDownList2.Items.Add("颐和园");
this.DropDownList2.Items.Add("雍和宫");
this.DropDownList2.Items.Add("红螺寺");
break;
case "上海":
this.DropDownList2.Items.Add("崇明岛");
this.DropDownList2.Items.Add("外滩");
this.DropDownList2.Items.Add("万佛阁");
break;
case "香港":
this.DropDownList2.Items.Add("海洋公园");
this.DropDownList2.Items.Add("半岛酒店");
break;
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
ShowResult();
} protected void Button1_Click(object sender, EventArgs e)
{
if (this.Calendar1.Visible)
SetupTheDate();
else
{
try
{
this.Calendar1.SelectedDate = DateTime.Parse(this.TextBox1.Text);
this.Calendar1.VisibleDate = this.Calendar1.SelectedDate;
}
catch
{
}
this.Calendar1.Visible = true;
}
} protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
SetupTheDate();
} private void SetupTheDate()
{
this.TextBox1.Text = this.Calendar1.SelectedDate.ToShortDateString();
this.Calendar1.Visible = false;
ShowResult();
} void ShowResult()
{
this.Label1.Text = "您选择" + this.TextBox1.Text + "去" + this.DropDownList2.SelectedValue;
UpdatePanel3.Update();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>演示使用基本的asp.net ajax功能</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>--请选择--</asp:ListItem>
<asp:ListItem>北京</asp:ListItem>
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>香港</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" />
</ContentTemplate>
</asp:UpdatePanel>
<br />
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
请输入日期:
</td>
<td>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table cellpadding="0" cellspacing="0">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="147px" Text="<%# DateTime.Now.AddDays(20).ToShortDateString() %>" />
<asp:Button ID="Button1" runat="server" Text="..." OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Calendar ID="Calendar1" runat="server" Visible="False" OnSelectionChanged="Calendar1_SelectionChanged"
BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px" DayNameFormat="Shortest"
Font-Names="Verdana" Font-Size="8pt" ForeColor="#663399" Height="200px" ShowGridLines="True"
Width="220px">
<SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
<SelectorStyle BackColor="#FFCC66" />
<TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
<OtherMonthDayStyle ForeColor="#CC9966" />
<NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
<DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
<TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt" ForeColor="#FFFFCC" />
</asp:Calendar>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
<hr />
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
result:
<asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Size="Small"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
要注意细节,认真学习细节。
要知道UpdatePanel也是回发整个页面的,因此它是重量级的、很慢的。不过它没有全部——仅仅局部——刷新html/dom而已。这与轻量级的ajax是不同的。对于轻量级的ajax,那么asp.net ajax架构仅仅支持在ScriptManager中声明调用asmx这一种通讯方式,它并不支持把原来的asp.net服务器控件在ajax上实现,因此asp.net ajax基本上对轻量级ajax编程仅有通讯作用,对web2.0的GUI编程则豪没有意义。