如何以编程方式更改C#中ProgressTemplate内的span文本?

Bru*_*que 5 html c# asp.net updateprogress

我有以下UpdateProgress:

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updCampos"
    DynamicLayout="true">
    <ProgressTemplate>
        <div class="carregando">
            <span id="sAguarde">Aguarde ...</span>&nbsp;&nbsp;<asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading.gif" />
        </div>
    </ProgressTemplate>
</asp:UpdateProgress>
Run Code Online (Sandbox Code Playgroud)

我需要更改嵌入"sAguarde"范围内的文本"Aguarde ..."内容后面的代码,但我不知道如何访问此跨度.语言是C#.

非常感谢您的帮助.

Mic*_* DN 8

只需<span>使用Label 更改您的控件,如下所示 -

<asp:Label id="sAguarde" Text="Aguarde ..." runat="server" />
Run Code Online (Sandbox Code Playgroud)

并从代码隐藏访问它如下 -

Label progressMessageLabel = UpdateProgress1.FindControl("sAguarde") as Label;
if (progressMessageLabel != null)
{
    progressMessageLabel.Text = "something";
}
Run Code Online (Sandbox Code Playgroud)


JAK*_*JAB 5

您可以将跨度更改为服务器端控件:

<span id="sAguarde" runat="server">Aguarde ...</span>
Run Code Online (Sandbox Code Playgroud)

然后你可以从代码隐藏中访问它:

protected override void Render(HtmlTextWriter writer)
{
    if (update) // globally declared update boolean to check if the page is being updated 
    {
        HtmlGenericControl sAguarde = (HtmlGenericControl) UpdateProgress1.FindControl("sAguarde");
        sAguarde.InnerHTML = "Hi";
    }
    base.Render(writer);
}
Run Code Online (Sandbox Code Playgroud)

但请注意,跨度的 id 将使用 ASP.NET 控件命名约定呈现。

有关完整上下文,请参阅:更改 UpdateProgress 控件的内容