import html file

Good Morning Experts,

Using the code behind, how would I import an html file into a aspx page on_load?

   - Marc
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm not sure why you are interested in doing this. You can always use an include statement in the code in front.

<!-- #include virtual="/somefile.html" -->

But if you need to include it in the code behind, you can use a streamreader.
MarcGraffAuthor Commented:
Good Afternoon strickdd,

We have different menus depending on the user. the menus are done in html because they are used in multiple languages. The reason I need this in the codebehind is so I can pull the correct menu for the correct user.

   - Marc

Instead of storing the different menus as html, why don't you store them as txt files. Strip out all the unecessary code (like head or body tags) if you haven't already...  

Then, in your code behind, figure out who the user is, figure out which menu to display for that user, and then read in the appropriate text file, and assign it to an inline variable or an asp label (if you can get away without having any issues becuse an asp label will add span tags around the text) following the advice of the following article for reading in txt files:

To specify one thing, by inline variable I mean the following
In your html design you add the following


In your code behind you register this variable as a protected string
In c# it looks like this: protected string Menu_HTML;
It goes right after the public class definition (where all the server controls are defined as protected)

Then in your code you can assign a value to the variable by simply doing something like

Menu_HTML = "This text will show up on your page whever you added the variable declaration";

Hope that helps....

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

I wouldn't recommend using a Literal control instead of the <%=Menu_HTML%>. It is the more ".Net way" of doing things. All you have to do is set the literalObj.Text = HTMLText.

To get the HTML text just use a streamreader on whatever file you have it saved as.
Another option, which is probably even better would be to use a masterpage with the different menus in it. Have the menues be in panels and then you can set the visibility to true or false depending on the user type.
A label control uses the property innerhtml that needs to be set and can be frustrating if you just select the .text property. With a literal you keep consistency by only setting .text properties.
MarcGraffAuthor Commented:
Thanks so much! I have it up are running perfectly!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.