为什么我不能更改我的 UpdateProgress div 下的标签?

Why can't I change the label under my UpdateProgress div?

<asp:UpdateProgress ID="PreLoader" runat="server" ClientIDMode="Static">
    <ProgressTemplate>
        <div class="divWaiting">
            <asp:Image ID="preload" runat="server" ImageUrl="/Images/preloader.gif" />&nbsp
            <asp:Label ID="pmtProc1" runat="server" Text="Payment Processing ... Please Wait" ></asp:Label>
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>

我似乎无法在我的代码隐藏中访问 pmtProc1,为什么?

页面不直接包含模板中的任何服务器端控件(例如 <asp:Repeater><asp:GridView><asp:UpdateProgress> 等所使用的控件)。

在这种情况下,您需要对 <asp:UpdateProgress> 控件本身执行 .FindControl...

例如...

Label pmtProc1 = (Label)PreLoader.FindControl("pmtProc1");
pmtProc1.Text = "New Text";

注意,这不适用于可以出现多个模板的控件(例如 <asp:Repeater><asp:GridView)...在这种情况下,您需要找到有问题的 item,然后在该项目中找到控件。

例如...

Label lbl = (Label)myRepeater.Items[0].FindControl("myLabel");