adding text to legend from code behind

2019-08-01 08:42发布

问题:

how can i add text to a legend from code behind

回答1:

Assuming you're talking about the HTML Legend Tag and using C# in an ASP.NET site. You can give it an ID and a runat="server" then you can access it from the code behind by name and change its text property.

<form id="form1" runat="server">
<fieldset>
<legend id="myLegend" runat="server">Personalia:</legend>
Name: <input type="text" size="30" /><br />
Email: <input type="text" size="30" /><br />
Date of birth: <input type="text" size="10" />
</fieldset>
</form>

Then in the code behind:

myLegend.InnerText = "Foo";


标签: c# .net legend