Comment modifier par programmation un texte span dans un ProgressTemplate en C# ?
-
21-12-2019 - |
Question
J'ai le UpdateProgress suivant :
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updCampos"
DynamicLayout="true">
<ProgressTemplate>
<div class="carregando">
<span id="sAguarde">Aguarde ...</span> <asp:Image ID="Image1" runat="server" ImageUrl="~/images/loading.gif" />
</div>
</ProgressTemplate>
</asp:UpdateProgress>
Je dois modifier le code derrière le contenu du texte "Aguarde..." que j'ai imbriqué dans la travée "sAguarde", mais je ne sais pas comment accéder à cette travée.Le langage est C#.
Merci beaucoup pour l'aide.
La solution
Changez simplement votre <span>
contrôle avec Label comme suit-
<asp:Label id="sAguarde" Text="Aguarde ..." runat="server" />
et accédez-y à partir du codebehind comme suit :
Label progressMessageLabel = UpdateProgress1.FindControl("sAguarde") as Label;
if (progressMessageLabel != null)
{
progressMessageLabel.Text = "something";
}
Autres conseils
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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow