简体   繁体   English

为什么我不能在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>

I can't seem to access pmtProc1 in my code-behind, why? 我似乎无法在代码隐藏区中访问pmtProc1 ,为什么?

Any server-side control within a template (as used by things like <asp:Repeater> , <asp:GridView> and <asp:UpdateProgress> for example) are not directly contained by the page. 页面中不包含模板中的任何服务器端控件(例如,诸如<asp:Repeater><asp:GridView><asp:UpdateProgress> <asp:GridView> )。

In this case you need to do a .FindControl on the <asp:UpdateProgress> control itself... 在这种情况下,您需要对<asp:UpdateProgress>控件本身执行.FindControl

For instance... 例如...

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

Note , this won't work with controls where multiple templates can occur (such as <asp:Repeater> and <asp:GridView for example)... in this situation you need to find the item in question and then find the control within that item. 请注意 ,这不适用于可以出现多个模板的控件(例如<asp:Repeater><asp:GridView )...在这种情况下,您需要找到有问题的item ,然后在其中找到控件该项目。

For instance... 例如...

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM