Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change programatically a span text inside a ProgressTemplate in C#?

I have the following 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>

I need to change in the code behind the text "Aguarde..." content that i nested inside the "sAguarde" span, but I don't know how to access this span. The language is C#.

Many thanks for the help.

like image 207
Bruno Albuquerque Avatar asked Feb 25 '14 14:02

Bruno Albuquerque


2 Answers

Just change your <span> control with Label as follows-

<asp:Label id="sAguarde" Text="Aguarde ..." runat="server" />

and access it from codebehind as follows-

Label progressMessageLabel = UpdateProgress1.FindControl("sAguarde") as Label;
if (progressMessageLabel != null)
{
    progressMessageLabel.Text = "something";
}
like image 86
Microsoft DN Avatar answered Sep 20 '22 14:09

Microsoft DN


You could change the span to a serverside control:

<span id="sAguarde" runat="server">Aguarde ...</span>

Then you can access it from the codebehind:

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);
}

But note that the span's id will be rendered using ASP.NET control naming conventions.

For full context, see: Changing the contents of the UpdateProgress control

like image 28
JAKEtheJAB Avatar answered Sep 20 '22 14:09

JAKEtheJAB