开发者

Inserting code from seperate source file (ASP.NET/C#)

How can I insert code into a page in ASP.Net from a seperate source file?

Say I have:

   <% 
 开发者_如何学JAVA        Response.Write("hello world");
   %>

How can I make it something like:

   <% include(helloworld.cs) %>

I know how it work sin the header with the <%@ and CodeFile= but I can't make it work for different spots of code. Is there a way ASP.Net handles this? I've tried googling but not sure what to search for.


Another option not mentioned yet is to use ASP.NET Master Pages. This is useful to have a consistent look and feel (and code behind) in the master page which extends to the child pages.


you could create a class library and add a reference to the library.

link that may help:

http://support.microsoft.com/kb/306575


You can use old-style Server-Side include tags like so:

<!-- #include virtual="/inc.inc" -->

But I do not recommend it. You should use User Controls instead; they give you more capability, and do not potentially expose server-side code if someone should happen to try to request them directly.

If you nevertheless decide to use includes like that, note that the content of the file is included in the ASPX/ASCX source code just as if you had typed it right in the main source file itself.


You can't shouldn't.

Instead, you should create a User Control.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜