【发布时间】:2013-01-23 19:37:03
【问题描述】:
我想刷新 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 页面启动用户控制时,一切正常。在从控制面板回发时,刷新用户控件(使用标签 + 时间检查),但没有值传递给用户控件。
【问题讨论】:
-
你能贴出用户控件的代码吗?至少处理
Length和ID在此上下文中的含义的部分,以及可能也更改这些值的任何代码隐藏代码。 -
@AnnL。我已经在代码后面发布了代码。
-
在用户控件中看不到对 Length 属性的引用。或者您的意思是您正试图以同样的方式使用这些其他属性?
-
我也是这样用的
标签: asp.net user-controls updatepanel