2

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 hope you understand my problem.

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer was a great help to me! Thanks a lot for the sources.
0

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

Comments

0

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.

Comments

0

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...

Comments

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.