动态在asp.net中包含文件 [英] dynamically includes file in asp.net

查看:58
本文介绍了动态在asp.net中包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

:confused:

.net是否允许在asp.net中动态包含文件?它是否可以应用在切换情况下,例如下面的菜单栏?

PHP文件包含在

<?php include(''include/footer.php''); ?>



我们可以使用开关盒,然后按以下菜单栏

< html>
< head></head>
< body>
< div class ="glossymenu2">
< a href ="index.php" class ="menuitem3"> Home</a>
< a href ="index.php?menu = 1" class ="menuitem3">关于我们</a>
< a href ="index.php?menu = 2" class ="menuitem3">特价商品</a>
</div>



<?php

开关($ _REQUEST [''menu''])
{

情况"1":
require_once"include/about_us.php";
休息;

case"2":
require_once"include/special_offer.php";
休息;


默认值:
require_once"include/introduction.php";
休息;


}

?>
</body>
</html>

谁能帮我? :doh:请!

:confused:

Is .net allows dynamically includes file in asp.net?Can it apply in switch case follow by menu bar like below eg ?

A php file is include by

<?php include(''include/footer.php''); ?>



and we can use switch case follow by menu bar as below

<html>
<head></head>
<body>
<div class="glossymenu2">
<a href="index.php" class="menuitem3">Home</a>
<a href="index.php?menu=1" class="menuitem3">About Us</a>
<a href="index.php?menu=2" class="menuitem3">Special Offer</a>
</div>



<?php

switch($_REQUEST[''menu''])
{

case "1":
require_once"include/about_us.php";
break;

case"2":
require_once"include/special_offer.php";
break;


default:
require_once"include/introduction.php";
break;


}

?>
</body>
</html>

can anyone help me? :doh: pls!

推荐答案

_REQUEST [''menu''])
{

情况"1":
require_once"include/about_us.php";
休息;

case"2":
require_once"include/special_offer.php";
休息;


默认值:
require_once"include/introduction.php";
休息;


}

?>
</body>
</html>

谁能帮我? :doh:请!
_REQUEST[''menu''])
{

case "1":
require_once"include/about_us.php";
break;

case"2":
require_once"include/special_offer.php";
break;


default:
require_once"include/introduction.php";
break;


}

?>
</body>
</html>

can anyone help me? :doh: pls!


ASP.NET中有菜单控件.您可以动态创建它们.您可以创建看起来像链接的链接按钮,但是可以回发并允许您运行switch语句(如果需要).您不能在ASP.NET中使用php文件.您可能想做的另一件事是,可以通过将所有三个项目添加为控件,并设置在switch语句中可见的一项来实现.您永远不会在PHP.NET中动态地在ASP.NET中包含代码,它是真正的编程.您将编写代码来控制显示的内容.

要修复破坏页面的代码,我所要做的就是将编辑器设置为自动检测(默认),然后将代码剪切并粘贴回编辑器中.备查.如果您在编辑器中输入HTML代码,只需剪切并粘贴使其成为HTML编码即可.

最后一点-我对显示/隐藏控件的回答是正确的,但更广泛地说,您需要忘记PHP的工作原理,因为这是一个丑陋的hack,ASP.NET的设计工作得更好,而且您也可以"如果您一直试图寻找使它像PHP一样运作的方法,那么只会限制您良好地使用它的能力.事实并非如此,这就是事实.
There are menu controls in ASP.NET. You can create them dynamically. You can create link buttons, which look like a link, but post back and allow you to run a switch statement if you want to. You cannot use php files in ASP.NET. The other thing you may be trying to do, you could do by adding all three items as controls, and setting which one is visible in your switch statement. You would never dynamically include code in ASP.NET, it''s real programming, not like PHP. You''d write code to control what was shown.

To fix your code, which broke the page, all I had to do was set the editor to auto detect ( the default ) and then cut and paste your code back into the editor. For future reference. If you type HTML code into the editor, just cut and paste it to cause it to be HTML encoded.

One final note - my answer about showing/hiding controls is correct, but more broadly, you need to forget how PHP works, as it''s all an ugly hack, ASP.NET is designed to work far better, and you''ll only limit your abilities to use it well, if you keep trying to find ways to make it act like PHP. The fact that it does not act that way, is what is so good about it.


这篇关于动态在asp.net中包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆