|
-
Mar 30th, 2007, 11:43 AM
#1
Thread Starter
Frenzied Member
Simple layout class
Alright, I'll give you a little background. I'm a PHP Developer being forced into an ASP.NET world... all I want to do is create a simple OOP approach to layout (header/footer/session management type stuff, etc).
I can handle the content but can someone give me a quick outline of how to create a class in ASP.NET?
I'm used to this:
Code:
<?php
/* =========================================================
Class Name: pagemaker
Creator: Bennet Oberholzer
Date: 9/13/2006
Usage: Preparing various portions of page interaction
========================================================= */
class pagemaker
{
var $page;
var $editor;
var $ajax;
var $insert;
var $title;
var $page_type;
var $errorcode;
function __construct($page, $page_type, $install)
{
$this->page = $page;
$this->page_type = $page_type;
$this->editor = 0;
$this->ajax = 0;
$this->title = "";
$this->insert = "";
$this->install = $install;
$this->logged_in = 0;
$this->errorcode = -1;
}
/**********************************************************************************************
FUNCTION head - opens connection, provides header graphic, sets up body element, includes nav
***********************************************************************************************/
function head()
{
global $config, $manage;
$ehandle = new sql_handler(2, "", $_SERVER['HTTP_HOST'] . "/" . $_SERVER['PHP_SELF']);
$this->errorcode = -1;
if($_REQUEST['req'] != 'loginuser' && $_REQUEST['req'] != 'logout')
$this->auto_login();
elseif($_REQUEST['req'] == 'loginuser')
$this->manual_login();
$this->redirect = 0;
$this->editor = 0;
$this->ajax = 0;
// stuff
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="B. Oberholzer" />
<link rel="stylesheet" type="text/css" href="style/sinorca-screen.css" media="screen" title="Sinorca (screen)" />
<?php
// LOAD MODULE'S JS
$query = "SELECT jsfiles FROM modules WHERE mod_name = '$this->page_type'";
$result = $ehandle->update_query($query);
if($result && mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
$jsarray = explode(';', $row['jsfiles']);
for($i=0;$i<count($jsarray);$i++)
echo '<script language="javascript" type="text/javascript" src="'.$mod_loc.'/'.$jsarray[$i].'"></script>';
}
<?php
}
// LOAD AJAX FRAMEWORK IF NEEDED
if($this->ajax == 1)
echo "<script language=\"javascript\" type=\"text/javascript\" src=\"js/qm.js\"></script>";
}
/**********************************************************************************************
FUNCTION foot - provides update specific information and closes off the page
***********************************************************************************************/
function foot()
{
global $config, $manage;
?>
<div id="footer">
// stuff
</div>
<?php
}
}
?>
And you call it like this:
Code:
$pg = new pagemaker($_SERVER['PHP_SELF'], $_REQUEST['req'], $loc['install_folder']);
$pg->head();
I'm not asking for someone to recreate that in ASP, but can someone give me a quick outline or point me in the direction of a tut that can show me how to recreate that in ASP.NET?
-
Mar 30th, 2007, 02:52 PM
#2
Thread Starter
Frenzied Member
-
Mar 30th, 2007, 05:26 PM
#3
Re: Simple layout class
To create a class, add a new class file to you solution using the Solution Explorer.
I'm coding in VB.NET. You didn't specify which language.
Code:
Public Class Pagemaker
Private _Page as Integer = 0
Private _Editor as Boolean = False
Private _Ajax as Boolean = False
Private _Insert as String = String.Empty
Private _Title as String = String.Empty
Private _Page_Type as Integer = 0
Private _ErrorCode as Integer = 0
Public Sub New() 'Default Counstructor
End Sub
Public Sub New(ByVal Page as Integer, ByVal Page_Type as Integer, ByVal Install as String) 'Overloaded Constructor
Me._Page = Page
Me._Page_Type = Page_Type
Me._Editor = False
Me._Ajax = False
Me._Title = String.Empty
Me._Insert = String.Empty
Me._Install = Install
Me._Logged_In = False
Me._ErrorCode = -1
End Sub
Public Sub Head()
' Do stuff
End Sub
And to instantiate this class from your web page code behind:
Code:
' Create an instance of the class
Dim MyPagemaker as New Pagemaker(1, 2, "something goes here related to install")
MyPagemaker.Head()
This will get you started. OOP in .NET its very powerful.
HTH,
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
-
Apr 2nd, 2007, 03:29 PM
#4
Thread Starter
Frenzied Member
Re: Simple layout class
Ugh... I can't see how anyone would willing code in this crap. Why do I need all these files and project crap? I just want a basic connection to a database and some simple class support. WHERE'S MY PHP?
-
Apr 5th, 2007, 06:09 AM
#5
Re: Simple layout class
You need it because of the ASP.NET architecture, for the purpose of compilation. I can understand the feeling of moving from a platform you love to a new platform and immediately assuming they should all work the same, but that is a misguided attitude. ASP.NET and PHP are different, they work different and ought to be used for different types of projects.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|