Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to PHP's include in C#

Tags:

c#

php

What is the equivalent command to PHP's include() in C# ?

For example, PHP's include is used as so : include("ex.php");

Can I do the same in C#?

like image 498
Amra Avatar asked Nov 15 '10 20:11

Amra


People also ask

What are include () and require () functions?

The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

What is PHP script look like C?

The simplest way to think of PHP is as interpreted C that you can embed in HTML documents. The language itself is a lot like C, except with untyped variables, a whole lot of Web-specific libraries built in, and everything hooked up directly to your favorite Web server.

Is C similar to PHP?

In terms of keywords and language syntax, PHP is similar to the C style syntax. if conditions, for and while loops, and function returns are similar in syntax to languages such as C, C++, C#, Java and Perl.

What is PHP full form?

PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language. PHP scripts are executed on the server.


2 Answers

If you mean in ASP.Net using C# you can create a user control (.ascx) and add it in your .aspx page.
If you are doing MVC you can create a partial view.

The closest thing I can think of would be after creating an ascx user control named "MyUserControl"

in your page_load or pre_render :

MyUserControl cont = new MyUserControl();
this.Controls.Add(cont);
like image 149
alexandrekow Avatar answered Sep 30 '22 19:09

alexandrekow


There is no such thing in C#. It's not a scripting language, so including a block of script wouldn't make sense.

What are you trying to accomplish? There are ways to do similar things in C#.

like image 20
John Saunders Avatar answered Sep 30 '22 18:09

John Saunders