1

I am trying to populate a string with some information from an include file and I'm not quite sure how I should go about doing this

Here's what i've got

someText = "text <!--#include file='/includes/myfile.aspx'--> text"

Can this be done?

At the moment it is just putting nothing in there

Thanks

2
  • Is that a string in Javascript or a string in the server code? Commented Apr 6, 2011 at 12:57
  • That's a string in the Asp.Net code Commented Apr 6, 2011 at 13:00

3 Answers 3

2

No, it's not possible to use an include inside a string.

Just load the contents from the file:

someText =
  "text " +
  File.ReadAllText(Server.MapPath("/includes/myfile.aspx")) +
  " text";
Sign up to request clarification or add additional context in comments.

1 Comment

I would still strongly recommend that you use a user control - you seem to be using a classic ASP approach to a problem that ASP.NET already has a solution for.
2

I think you probably want to be using a UserControl there.

See here: ASP.NET User Controls

Comments

0

You can't directly do this with ASP.NET. It depends if you have logic in the myfile.aspx or not which way would be the best way to go.

2 Comments

I use the include on loads of different pages - we update this include regularly so would like to still use it - is there not a way around it?
All that's in the include is HTML <p></p> tags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.