Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 728507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:41:22+00:00 2026-05-14T06:41:22+00:00

I feel somewhat foolish asking such a simple question, but I can’t seem to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:41:22+00:00Added an answer on May 14, 2026 at 6:41 am

    The easiest way to do this is to create a string variable or property in your code-behind class and use the <%= %> notation (short for Response.Write) to render it on your page inline:

    // You can do this anywhere on your .aspx, as many times as you like.
    <%= this.CompanyName %>
    
    // Better yet, html encode the value to protect against various threats,
    // such as cross-site script injection (XSS)
    <%= HttpUtility.HtmlEncode(this.CompanyName) %>
    

    .NET 4.0 introduces a new shortcut notation (Html Encoding Blocks) to html-encode your output:

    <%: this.CompanyName %>
    

    Regarding your original approach, ASP.NET web controls like Literal represent individual parts of a web page – you can’t use them multiple times on a page because the object instance company_name refers to the specific part of the HTML generated by the <asp:literal> in your .aspx page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I feel stupid asking this question, but I can not find a clear answer
I am somewhat new to Jquery but I feel complete failure here at not
I know this question has been somewhat dealt with before, but I feel like
I feel my question is quite basic, but I couldn't find any related SO
I feel like I'm re-inventing the wheel here, but I need to find a
I'm somewhat new at C++ (I normally work in C#, but right now I'm
This is somewhat of a broad question, but it is one that I continue
I apologize in advance for this somewhat ignorant question, but I have researched this
Yes this is a pretty general question but I'm trying to get a feel
So I am still somewhat new to PHP, MySQL, and Javascript but I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.