asp.net include page like php
im starting to learn asp.net :P, and in php i should use include(); to show something like a menu. but how can i do this in asp.net?
i dont mean a simple include, but a page where i can query a database to make the page dynamicly for example.
i h开发者_如何学Goope you understand my problem.
You do this by Developing a Simple ASP.NET Server Control. Before that read ASP.NET Server Control Development Basics
And then it will be just as easy as doing
<%@ Register TagPrefix="stefanControls" Namespace="stefanNamespace" Assembly = "stefanAssembly" %>
<html>
<body>
<form runat=server>
Here is a custom ASP.NET server control.<br><br>
<stefanControls:MenuBar Depth="2" runat=server/>
<br>
</form>
</body>
</html>
with your page template.
Rather than trying to write ASP.NET code like PHP (and using include files), I would recommend creating a user control (.ascx) for the content that you want to dynamically render, and dropping that onto your page. You can write the code to retrieve dynamic content for the control in the code-behind.
More info: http://msdn.microsoft.com/en-us/library/y6wb1a0e.aspx
Use Custom Server Controls, or Master Pages. Both are a bit unusual at first if coming from PHP/Classic ASP, but they are great and make your life a lot easier.
Well,you could create a Class (.cs) for these purposes and create a function such as
class MyClass
{
public static string GenerateHTML()
{
string html="";
html = "<Your HTML>";
return html;
}
}
and just call MyClass.GenerateHTML() wherever you want to have that HTML placed.....This method is much similar to include in PHP........for including HTML content and obviously this method is good for defining all common functions as well...
精彩评论