Saturday, March 31, 2012

Similar method from PHP?

Is there anyway I can include ASP.NET documents like in PHP. Im converting my website to ASP.NET from PHP and theres a few things im stuck on.
How would I convert this?:
<?PHP
error_reporting (E_ALL ^ E_NOTICE);
if(!$page){ $page = $HTTP_GET_VARS['page']; }

if($page=="" or $page=="news" or $page=="main" or $page=="home"){
include("main.php");
}elseif($page=="contact"){
include("company_contact.php");
}elseif($page=="about"){
include("company_about.php");
}elseif($page=="press"){
include("company_press.php");
}
?>You don't have includes in asp.net as you did on PHP.

You have user controls (.asmx) that use a placeHolder to include them. They are very good, you should check them out if you haven't already.

Dim sPage as String = Request.QueryString("page")
Dim ascx As New UserControl

If sPage = String.Empty OrElse sPage = "news" OrElse sPage = "main" OrElse sPage = "home" Then
ascx = CType(Page.LoadControl("main.ascx"), UserControl)
ElseIf sPage = "contact"
ascx = CType(Page.LoadControl("contact.ascx"), UserControl)
ElseIf sPage = "about"
ascx = CType(Page.LoadControl("about.ascx"), UserControl)
ElseIf sPage = "press"
ascx = CType(Page.LoadControl("press.ascx"), UserControl)
End If

placeHolder1.Controls.Add(ascx)

HTH
HoraShadow

0 comments:

Post a Comment