Ajax UpdatePanel刷新的问题

scfobao 2008-12-17 08:36:05

在我的页面中有两个Panel
一个panel中放置了产品列表供给PopupControlExtender1弹出,选择的值返回给产品TextBox
另一个Panel中放置了一个Canlendar,由PopupControlExtender2弹出,选择的值返回给日期TextBox
两个Panel中都放置有UpdatePanel ,产品列表和Canlendar都放置在<contentTemplate></contentTemplate>中

在另一个UpdatePanel(UP3)中放置了一个Repeater,其DataSourceID指定为一个提供次品类型的SqlDataSource,
当页面第一次载入时,显示某某次品类型和一文本框等待输入次品数量;当产品和日期都选择了之后,希望能根据其将对应的
次品数量显示出来。

我用了两个方法均不行,
1、我用sm1.RegisterAsyncPostBackControl(Button1);注册了一个Button,
2、在PopupControlExtender.Commit()之后调用up3.update()


以下是源代码,请各位大佬帮忙

<%@ Control Language="C#" ClassName="spc" %>
<%@ Import Namespace="admin" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">
private SqlConnection conn;
private string cmdtext;
private DataSet dataset;

protected void Page_Load(object sender, EventArgs e)
{
string connstr = new conn().constr();
dataset = new DataSet();
//cmdtext = "select * from TB_cptype where ID<>28 order by ID";
conn = new SqlConnection(connstr);
conn.Open();
sm1.RegisterAsyncPostBackControl(Button1);
//new SqlDataAdapter(cmdtext,this.conn).Fill(dataset,"cp");
//Repeater1.DataSource=dataset.Tables["cp"].DefaultView;
//Repeater1.DataBind();
cmdtext = "select pn,ID from TB_products order by ID";
new SqlDataAdapter(cmdtext, conn).Fill(dataset, "pn");
rbl_PN.DataSource = dataset.Tables["pn"].DefaultView;
rbl_PN.DataTextField = "pn";
rbl_PN.DataValueField = "ID";
rbl_PN.DataBind();
}

protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
TextBox txtcp = (TextBox)e.Item.FindControl("txt1");
Label lbltypename=(Label)e.Item.FindControl("typename");

//Mytools.print(txtPN.Text);

//if (txtcp == null)
//{
// txtcp = (TextBox)e.Item.FindControl("txt" + lbltypename.Text);
// tmp = "txtcp=null";
//}
//txtcp.ID = "txt" + lbltypename.Text;

txtcp.Text = txtcp.Text + DateTime.Now.ToLocalTime().ToString();


}



protected void calDay_SelectionChanged(object sender, EventArgs e)
{

pce1.Commit(calDay.SelectedDate.ToShortDateString());
// Repeater1.DataBind();
// up3.Update();
}

protected void txtsearch_TextChanged(object sender, EventArgs e)
{


cmdtext = "select pn,ID from TB_products where pn like '%"+txtsearch.Text+"%' order by ID";
new SqlDataAdapter(cmdtext, conn).Fill(dataset, "pn1");
rbl_PN.DataSource = dataset.Tables["pn1"].DefaultView;
rbl_PN.DataTextField = "pn";
rbl_PN.DataValueField = "ID";
rbl_PN.DataBind();
}

protected void rbl_PN_SelectedIndexChanged(object sender, EventArgs e)
{

pce2.Commit(rbl_PN.SelectedItem.Text);
// Repeater1.DataBind();
//up3.Update();
rbl_PN.ClearSelection();

}


protected void Repeater1_Load(object sender, EventArgs e)
{
Repeater rep = (Repeater)sender;
for (int j = 0; j <= rep.Items.Count - 1; j++)
{
TextBox txtcp = (TextBox)rep.Items[j].FindControl("txt1");
Label lbltypename = (Label)rep.Items[j].FindControl("typename");
txtcp.Text =txtcp.Text+ DateTime.Now.ToShortTimeString();
}
//Mytools.print(txtPN.Text);

//if (txtcp == null)
//{
// txtcp = (TextBox)e.Item.FindControl("txt" + lbltypename.Text);
// tmp = "txtcp=null";
//}
//txtcp.ID = "txt" + lbltypename.Text;



}

protected void Button1_Click(object sender, EventArgs e)
{
Repeater1.DataBind();
//Repeater rep = (Repeater)sender;
//for (int j = 0; j <= Repeater1.Items.Count - 1; j++)
//{
// TextBox txtcp = (TextBox)Repeater1.Items[j].FindControl("txt1");
// Label lbltypename = (Label)Repeater1.Items[j].FindControl("typename");
// txtcp.Text = txtcp.Text + DateTime.Now.ToShortTimeString();
//}
// up3.Update();
}
</script>
<asp:ScriptManager ID="sm1" EnablePartialRendering="true" runat="server"></asp:ScriptManager>
<asp:Panel ID="p2_PN" Width="150px" BackColor="ActiveBorder" BorderColor="GhostWhite" BorderStyle="Solid" runat="server">
<asp:UpdatePanel ID="up2" ChildrenAsTriggers="true" UpdateMode="Conditional" runat="server" >
<ContentTemplate>
搜索:<asp:TextBox ID="txtsearch" AutoPostBack="true" Width="80px" runat="server" OnTextChanged="txtsearch_TextChanged"></asp:TextBox>
<asp:RadioButtonList ID="rbl_PN" AutoPostBack="true" runat="server" OnSelectedIndexChanged="rbl_PN_SelectedIndexChanged">
</asp:RadioButtonList>
</ContentTemplate>

</asp:UpdatePanel>
</asp:Panel>

<asp:Panel ID="p1" runat="server">
<asp:UpdatePanel ID="up1" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Calendar ID="calDay" runat="server" OnSelectionChanged="calDay_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>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>

<cc1:PopupControlExtender ID="pce1" PopupControlID="p1" TargetControlID="txtCalendar" Position="Right" CommitProperty="value" CommitScript="e.value" runat="server" >
</cc1:PopupControlExtender>
<cc1:PopupControlExtender ID="pce2" PopupControlID="p2_PN" TargetControlID="txtPN" Position="Right" CommitProperty="value" CommitScript="e.value" runat="server" >
</cc1:PopupControlExtender>

<table width="80%" cellpadding=0 cellspacing=0>
<tr>
<td>请选择产品</td>
<td>
<asp:TextBox ID="txtPN" runat="server"></asp:TextBox>

</td>

</tr>
<tr style="background-color:LightGray">
<td>请选择日期</td>
<td><asp:TextBox ID="txtCalendar" runat="server"></asp:TextBox></td>
<asp:Label ID="lblmsg" runat="server"></asp:Label></tr>

<asp:UpdatePanel ID="up3" runat="server" >
<ContentTemplate>
<asp:Repeater ID="Repeater1" DataSourceID="sds_Input" runat="server" OnItemDataBound="Repeater1_ItemDataBound" OnLoad="Repeater1_Load">

<AlternatingItemTemplate>
<tr style="background-color:LightGray">
<td><%#Eval("descript")%><asp:Label ID="typename" runat="server" Text='<%#Eval("typename") %>' Visible="false"></asp:Label></td>
<td><asp:TextBox ID="txt1" runat="server"></asp:TextBox></td>

</tr>
</AlternatingItemTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("descript")%></td>
<td><asp:TextBox ID="txt1" runat="server"></asp:TextBox><asp:Label ID="typename" runat="server" Text='<%#Eval("typename") %>' Visible="false"></asp:Label></td>

</tr>
</ItemTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="sds_Input" runat="server" SelectCommand="select * from TB_cptype where ID<>28" ConnectionString="<%$ ConnectionStrings:TwebConnectionString %>" ProviderName="<%$ ConnectionStrings:TwebConnectionString.ProviderName %>" ></asp:SqlDataSource>

</ContentTemplate>

</asp:UpdatePanel>
</table>
<asp:But
...全文
2243 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
scfobao 2008-12-17
<asp:But
应该是
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
回复
yefengzhixia 2008-12-17
顶了

刚建立了一个C#群 63242231 希望有志同道合的朋友加入 共同学习 谢谢。。。
回复
相关推荐
发帖
.NET技术社区
创建于2007-09-28

5.8w+

社区成员

.NET技术交流专区
申请成为版主
帖子事件
创建了帖子
2008-12-17 08:36
社区公告
暂无公告