我想刷新 UpdatePanel 中的用户控件,但我也想用不同的属性值刷新它。
<asp:UpdatePanel runat=server ID=up1>
<Triggers>
<asp:AsyncPostBackTrigger controlid="but01" eventname="Click" />
</Triggers>
<ContentTemplate>
<asp:Button runat="server" Text="Test" ID="but01" />
<UC:Uc runat=server ID="Uc1" />
</ContentTemplate>
</asp:UpdatePanel>
Codebehind for but01 click is
void but01_Click(object sender, EventArgs e)
{
this.Uc1.ID = 1;
this.Uc1.Length = 50;
}
我测试了这段代码,并且正在刷新用户控件,但未应用新值 ID=1、Length=50。
后面的控制代码比较简单
namespace Admin.Web.Controls
{
public partial class Uc1 : System.Web.UI.UserControl
{
private string p_to;
private string p_from;
private string p_subject;
private string p_body;
private string p_priority;
}
protected void Page_Load(object sender, EventArgs e)
{
this.txtFrom.Text = p_from;
this.txtTo.Text = p_to;
this.txtSubject.Text = p_subject;
this.txtBody.Text = p_body;
}
public string Subject
{
get
{
return p_subject;
}
set
{
p_subject = value;
}
}
public string From
{
get
{
return p_from;
}
set
{
p_from = value;
}
}
public string To
{
get
{
return p_to;
}
set
{
p_to = value;
}
}
public string Body
{
get
{
return p_body;
}
set
{
p_body = value;
}
}
}
ascx 标头是
<%@ Control Language="c#" Inherits="Admin.Web.Controls.Uc1" AutoEventWireup="true" Codebehind="Uc1.ascx.cs" %>
当我在页面加载期间从 aspx 页面启动用户控件时,一切正常。在从控制面板回发时,刷新用户控件(使用标签 + 时间检查),但没有值传递给用户控件。