Reuse ASP.NET Control Multiple Times on Page

Posted by macinjosh on Stack Overflow See other posts from Stack Overflow or by macinjosh
Published on 2010-04-19T17:18:23Z Indexed on 2010/04/19 17:23 UTC
Read the original article Hit count: 280

Filed under:
|
|

I feel somewhat foolish asking such a simple question, but I can't seem to find an answer. I'm new to ASP.NET (C#), but I'm learning by building a simple set of web pages that display a report. I have a variable that represents a company name. I need to output this variable in multiple places on the web page. The only way I have found to output a variable this is with:

company_name.Text = "Acme Windows";

then

<asp:literal id="company_name" runat="server" />

My problem is that I want to use company_name in multiple places on the page. Do I really have to create a separate variable holding the the same value for each time it is placed on the page? If I just copy the above XML code to all the places I want to show the variable it obviously creates a compile error since that ID is already defined.

I feel like I'm missing something very obvious.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about templates