UpdatePanel不能更新

xjjwmsj18 2011-07-11 10:34:29
前台:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<title></title>
<link href="/CSS/Verson2.0/Common.css" rel="stylesheet" type="text/css" />
<link href="/CSS/Verson2.0/css.css" rel="stylesheet" type="text/css" />
<script src="/JavaScript/jquery-1.5.js" type="text/javascript"></script>
<style type="text/css">
.style1
{
width: 300px;
}
.style2
{
width: 138px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
ChildrenAsTriggers="False">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="i1" runat="server">

<table class="style1">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server" Width="145px" AutoPostBack="True"></asp:TextBox>
</td>
<td class="style2">
<asp:DropDownList ID="DropDownList1" runat="server" Height="16px" Width="238px"
AutoPostBack="True" >
<asp:ListItem Text="没法定假期" Value="0"></asp:ListItem>
<asp:ListItem Text="有法定假期" Value="1"></asp:ListItem>
<asp:ListItem Text="没法定假期周末周日休息" Value="2"></asp:ListItem>
<asp:ListItem Text="有法定假期也周末周日休息" Value="3"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="刷新2" Width="107px"
onclick="Button2_Click" />
</td>
<td class="style2">
<asp:DropDownList ID="DropDownList3" runat="server" Height="16px" Width="238px" AutoPostBack="True" >
<asp:ListItem Text="没法定假期" Value="0"></asp:ListItem>
<asp:ListItem Text="有法定假期" Value="1"></asp:ListItem>
<asp:ListItem Text="没法定假期周末周日休息" Value="2"></asp:ListItem>
<asp:ListItem Text="有法定假期也周末周日休息" Value="3"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>

</div>
</ContentTemplate>
</asp:UpdatePanel>
<p> </p>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"
ChildrenAsTriggers="False">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="i2" runat="server">

<table class="style1">
<tr>
<td>
<asp:TextBox ID="TextBox2" runat="server" Width="147px" AutoPostBack="True"></asp:TextBox>

</td>
<td>
<asp:DropDownList Width="238px" ID="cdlGeneral" runat="server"
AutoPostBack="True" >
<asp:ListItem Text="没法定假期" Value="0"></asp:ListItem>
<asp:ListItem Text="有法定假期" Value="1"></asp:ListItem>
<asp:ListItem Text="没法定假期周末周日休息" Value="2"></asp:ListItem>
<asp:ListItem Text="有法定假期也周末周日休息" Value="3"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="刷新1"
Width="111px" />
</td>
<td>
 </td>
</tr>
</table>

</div>
</ContentTemplate>
</asp:UpdatePanel>

</form>
</body>
</html>

后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DropDownList1.Items[1].Selected = true;

DropDownList3.Items[1].Selected = true;

cdlGeneral.Items[1].Selected = true;
}

protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = DropDownList1.SelectedItem.Text;
UpdatePanel2.Update();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = cdlGeneral.SelectedItem.Text;
UpdatePanel1.Update();
}
}
...全文
93 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjjwmsj18 2011-07-12
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 xjjwmsj18 的回复:]
引用 7 楼 sp1234 的回复:
不管客户端选择哪一项,你都给改成第一项了。

我把后台代码中
//DropDownList1.Items[1].Selected = true;

//DropDownList3.Items[1].Selected = true;

//cdlGeneral.Items[1].Selected = true;注释掉,单击Button1和Button2都是刷新TextBox1的值,我的设计是单击Button1刷新TextBox2的值,单击Button2刷新TextBox1的值,可是我怎么调
单击Button1和Button2都是刷新TextBox1的值.[/Quote]

我知道什么原因了 是因为<asp:Button ID="Button1" runat="server" Text="刷新2" Width="107px" onclick="Button2_Click" /> 我的Button1 不小心把单击事件定义成Button2的单击事件了onclick="Button2_Click"
xjjwmsj18 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 sp1234 的回复:]
不管客户端选择哪一项,你都给改成第一项了。
[/Quote]
我把后台代码中
//DropDownList1.Items[1].Selected = true;

//DropDownList3.Items[1].Selected = true;

//cdlGeneral.Items[1].Selected = true;注释掉,单击Button1和Button2都是刷新TextBox1的值,我的设计是单击Button1刷新TextBox2的值,单击Button2刷新TextBox1的值,可是我怎么调
单击Button1和Button2都是刷新TextBox1的值.
  • 打赏
  • 举报
回复
不管客户端选择哪一项,你都给改成第一项了。
  • 打赏
  • 举报
回复
page_load里边去再设置 Selected Item?那么客户端提交的怎么可能正常反应到 DropDownList1.SelectedItem.Text 这类上来呢?
xjjwmsj18 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wxr0323 的回复:]
先看看这篇文章

参考
[/Quote]

看了 我把前台
<link href="/CSS/Verson2.0/Common.css" rel="stylesheet" type="text/css" />
<link href="/CSS/Verson2.0/css.css" rel="stylesheet" type="text/css" />
<script src="/JavaScript/jquery-1.5.js" type="text/javascript"></script>
这3行删除了,单击Button1和Button2都是刷新TextBox1的值,我改动了任何DropDownList值后,单击Button1和Button2连TextBox1的值都不刷新了,单击Button1和Button2页面毫无反应.
xjjwmsj18 2011-07-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 fengyarongaa 的回复:]
你有事件触发吗?
你怎么知道不能更新
[/Quote]

恩TextBox2.Text 没有变化
xjjwmsj18 2011-07-11
  • 打赏
  • 举报
回复
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
ChildrenAsTriggers="False">
我是设置成不能自动更新

只能使用后台的代码更新
protected void Button1_Click(object sender, EventArgs e)
{
TextBox2.Text = DropDownList1.SelectedItem.Text;
UpdatePanel2.Update();
}
没修改DropDownList的值可以更新TextBox1.Text的值,修改了任何DropDownList值后就不能更新了.
ycproc 2011-07-11
  • 打赏
  • 举报
回复
你有事件触发吗?
你怎么知道不能更新
子夜__ 2011-07-11
  • 打赏
  • 举报
回复
先看看这篇文章

参考

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧