我的代码如下。
<div class="table">
<asp:UpdatePanel runat="server" ID="labelPanel" UpdateMode="Conditional" >
<ContentTemplate>
<asp:Label Text="" runat="server" ID="Cost"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<uc1:ucPartsListing ID="ucPartsListing" runat="server" />
</div>
现在usercontrol ucPartsListing本身有2个更新面板。在某些情况下,有一个事件从用户控件触发到父aspx。
在那种情况下,我试图设置aspx文件中存在的标签值。我从代码隐藏手动调用更新。 然而它不起作用。我哪里错了?
public partial class PartsEnquiry : BaseAuthPage
{
protected void Page_Load(object sender, EventArgs e)
{
ucPartsListing.OnQuotePartsItemSelect += new ascx.ucPartsListing.QuotePartsItemEventHandler(ucPartsListing_OnQuotePartsItemSelect);
}
void ucPartsListing_OnQuotePartsItemSelect(string price)
{
Cost.Text = price; //This is not working !
labelPanel.Update();
}
答案 0 :(得分:0)
在“void ucPartsListing_OnQuotePartsItemSelect(string price)”方法上设置一个断点,看看它是否被击中。 我不确定您正在使用的用户控件是什么,但无论控制它应该触发事件,请尝试将其AutoPostBack属性设置为True。
答案 1 :(得分:0)
我认为你对目前的结构感到不快。
当您在浏览器中触发用户控件内的UpdatePanel时,它将更新页面内部的部分。您无法更新正在执行的UpdatePanel之外的控件。
在外部UpdatePanel上手动调用Update()
方法将无济于事,因为在客户端上它仍然是接收输出并更新html树的内部UpdatePanel之一。
要使其工作,您必须以某种方式触发外部UpdatePanel,它将能够更新Cost标签。