You are currently browsing the category archive for the 'intermediate' category.

I made the most interesting discovery today at work! Par for the course, Microsoft has left little to be desired from the documentation on MasterPages and actually leveraging their fullest potential. Today, I believe I have stumbled upon a small sieve into the potential power MasterPages have.

First I want to explain a few details, an example of sorts in the form of a scenario:

Suppose you have a web project and on the main page you want to display multiple areas of content, not necessarily related to one another. Say you have a header, body and footer – each containing dynamic content pertinent to their own function. In ASP.NET 1.1, it would be easy to just create user controls and place a single line of code for each element in the code and include an @ directive for each user control. Or for an even older example, use includes in classic ASP. Now, ASP.NET 2.0 comes along and introduces MasterPages and ContentPlaceHolders! Such a simple and effective solution one would think!!

Because of the way our brains have wrapped around includes in classic ASP and user controls in 1.1, we think that somehow 2.0 renders from the MasterPage down to the pages themselves – thus rendering every page. But this doesn’t work. For if you were to actually try to add more than one ContentPlaceHolder into the MasterPage and render different .aspx pages within, you’d quickly discover that not all the ContentPlaceHolders render on the page when you browse out to them. *scratches head* Hmm… So, you’ll need to set each of the 3 ContentPlaceHolder’s in each rendered page (in this case, default.aspx) in the form of <asp:Content> tags. When I first saw this example, I thought – but that’s NOT what I wanted it to do! That’s not how I expected it to code out as. I figured the MasterPage should serve out this content. After all, it’s the MasterPage that has the ContentPlaceHolders! It just didn’t seem right to me.

Then it hit me: What actually happens is that the page renders from the bottom up: The page that is called, such as in “http://localhost/default.aspx”, default.aspx is called and rendered, rendering each of the <asp:Content> tags which have attributes telling us where in what MasterPage they should be rendered in. Then, the MasterPage that is attributed in the Page directive of default.aspx is called and rendered.

Basically, the page (default.aspx) could be nothing more than a “staging area” as we might call it in the military. It would tell the server what MasterPage it belongs to and it would tell the MasterPage what ContentPlaceHolders to render in it’s code. This is where 1.1 collides with 2.0:

MasterPage.Master has the following:

  • cphHeader as ContentPlaceHolder control
  • cphBody as ContentPlaceHolder control
  • cphFooter as ContentPlaceHolder control


<body>
<form id="form1" runat="server">
<div>
<asp:contentplaceholder id="cphHeader" runat="server">
</asp:contentplaceholder>
<asp:contentplaceholder id="cphBody" runat="server">
</asp:contentplaceholder>
<asp:contentplaceholder id="cphFooter" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>

Default.aspx has the following:

  • In the @Page directive, assign the MasterPage to which default.aspx belongs to
  • Each of the <asp:Content> tags assigned to their respective ContentPlaceHolder
  • To cut to the chase, the <asp:Content> tags have User Controls in them which helps you manage your code more fluidly


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphHeader" Runat="Server">
<ctrl:Header ID="ctrlHeader" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cphBody" Runat="Server">
<ctrl:Body ID="ctrlBody" runat="server" />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphFooter" Runat="Server">
<ctrl:Footer ID="ctrlFooter" runat="server" />
</asp:Content>

web.config has the following:

  • Look to <system.web><pages><controls> node and add the User Control tags for global use of the Controls


<system.web>
<pages>
<controls>
<add tagPrefix="ctrl" tagName="Header" src="~/Controls/ctrlHeader.ascx" />
<add tagPrefix="ctrl" tagName="Body" src="~/Controls/ctrlBody.ascx" />
<add tagPrefix="ctrl" tagName="Footer" src="~/Controls/ctrlFooter.ascx" />

<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" tagPrefix="ajaxToolkit"/>
</controls>
</pages>
</system.web>

Then, each of the User Controls files have their own unique html which when rendered, is completed as one long string of code, just like with classic ASP’s Includes and ASP.NET 1.1’s User Controls.

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctrlBody.ascx.cs" Inherits="Controls_ctrlBody" %>
<div>This is the Body in a UserControl.</div>

What’s really great about this approach is that you can still programmatically call the user controls based on condition or whatever all in your codebehind! In the default.aspx file, if I didn’t want to see one of the User Controls, I can simply hide it’s visibility. The possibilites are endless!

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (1 > 0)
ctrlBody.Visible = false;
}
}

Since 1 is always greater than 0 (duh!), the output would look like this:

MasterPage Tutorial Screen Capture

“f u cn rd ths, u cn gt a gd jb n cmptr prgmmng.” – Anon

Thanks, capella07, for the quote.

Microsoft Surface will use Silverlight and you can try out what it’s like here. Only thing is that without the Surface Hardware support, the UI is more of a click and drag effect. I can’t wait to try this on a real Surface Hardware setup!

Thanks, Delay, for the blog entry.
(bs.)

Creative flash websites are generally (I say generally, because there are plenty of horribly talented individual out there that can develop complete and gorgeous sites fully within Flash itself) designed first in a graphics editor then each layer is saved off into a separate PNG file which then are imported ever so tediously into Flash’s library and placed on the stage for development of the site. This, if the graphic is at all intricate, can be is VERY daunting. This is the single most hated chore I face when developing a Flash animated site for a client.

If you’ve read any of my other posts, you’ll be sure to note that I am very fond of Lynda’s Online Training Library and am a current subscriber. Recently, in one of the videos I was watching as a refresher to the Flash IDE, I came across this little plugin that promised to save tedious time, painstaking tasks while freshening your breath (seriously, it promises to freshen your breath and it’ll even floss for you, too)! MediaLab’s PSD2FLA Photoshop PluginHaving already fairly fresh breath, I decided to give the other two claims a go of it and I tested the plugin’s promises against a rather large client file I had developed in Photoshop CS. I was anxious to see how well it would actually import the layers into flash and how accurately it would place them on the stage. The Lynda video’s instructor was on a Windows platform; and for reasons which I do not understand, Photoshop and Flash have tendencies to perform differently and interact with inconsistent results than they do on a Mac platform. Sometimes, for the better, other times it is altogether counter-intuitive to the environment. One such example where Windows is favored is when you import a PSD file from Photoshop into Flash using one of the many ways demonstrated in the Video Library, Flash will organize the layers appropriately. However, in a Mac environment, for one reason or another, the layers are hardly ever organized in the proper order. This leaves the developer with more work in the long run.

After retrieving the download, the installation was a cinch; intuitive, simple and quick! I opened my client’s PSD and saved off a copy that I would work with (protecting the valuable work I had already done from being destroyed) then went to ‘File > Export > PSD2FLA’ and clicked ‘OK’ and left to get some coffee. I honestly don’t know how long it took to run the program, but when I came back, I was PLEASANTLY surprised to find that all the layers had, indeed, been imported in proper order! But, wait – what’s this?? Layer effects do not import gracefully? That was not good, I use layer effects quite a lot.

PSD2FLA App Screenshot

Thankfully, MediaLab has a great forum with eager and willing developers who will answer your questions with haste! The answer was simple: Merge the layer with the effects with a blank, empty layer from above (Command + E while selected on the blank layer placed above the layer with the effects). The only problem is that this renames your carefully and beautifully thought out name for your layer to ‘Layer #’ – how bland! And if there are many layers? Ugh…

MediaLab to the rescue again! They have a script that will do this to all layers within a PSD for you! And it works quite well… The only problem is that when they emailed the code snipet to me, I hadn’t the foggiest that it should be saved off into a separate file in JavaScript format. I examined the code and deduced that it was in fact JavaScript and saved it accordingly and then opened my PSD, once again, and chose ‘File > Script > Browse’, found the file, executed it and watched is loop through the file, flattening all the layers and maintaining their layer names all the while! Phew! Again, way to go, MediaLab. After then taking that altered PSD and running the PSD2FLA Export command again, it placed it within Flash in a matter of seconds with all the layer effects in proper display. I am quite a happy designer! Now I can focus on development and not on tedious, monotonously time wasting work.

This company is WELL worth the investment and investigation!
(bs.)

Link to the compressed file for automating the flattening and merging of Layers with Effects: YOU MUST RENAME THE DOCUMENT FROM .DOC TO .JS

I’ve had a dickens of a time finding support for Virtual Hosting on Apache Web Server specifically for Win 2k3 Server – Mostly what I’ve found has been related to Virtual Hosting on Apache in a *nix environment. Those documents help a bit, but the problem comes in when the documentation wants me to send a command to the console and I’m not using *nix.

First, admittedly so, I am a total Newb to Apache and OSI development. I can effectively administer IIS and Win 2k3 Server on a level becoming my title of Senior Consulting Engineer, but never have I actually gotten to the nuts and bolts of Apache. In IIS, quite simply one would add the new website, specify it’s document directory, assign any host headers to the IP and perhaps set the default documents. Outside of that, a little DNS configuration may be in order.

I have three domain names pointing to my single static IP address, for the purpose of this article, they can be domain1.com, domain2.com and domain3.com.

Having already had the 3 domains configured in IIS and viewable by the outside world, DNS has been configured and all the routing has been taken care of. I’ve uninstalled IIS and Apache’s Win32 installer works wonderful! After installing Apache 2.2.4, I installed ApacheConf; a GUI based application for administering Apache. It’s been great because it’s helped me know where to put the lines of code in the httpd.conf file, the configuration file for administering the web server.

Everywhere I’ve read online kept serving up pages talking about the following blocks of code:

<VirtualHost 10.1.2.3>
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
</VirtualHost>

The block that I’ve used looks like this:

<VirtualHost domain1.com:80>
ServerName domain1.com
DirectoryIndex index.html
DocumentRoot "E:/dir/to/my/www/files"
ServerAlias www.domain1.com
</VirtualHost>

Line 0 shows that I’m setting up a VirtualHost directive and it’s domain name and port number at which it will reside at. Line 1 and 2 further specify those settings. Line 3 is the root directory where the default document – or Directory Index – will be found along with the rest of the files for this domain. Line 4 allows you to specify any aliases that will also point to the specified repository. Lastly, line 5 closes the XML formatted block of code.

I repeated the block above for each domain I was configuring but when I tried to browse to any of those domains, I received a 403 Forbidden error. I searched and searched. Mostly, Google turned back sites that informed me to adjust the file permissions to allow “apache” access to the files, but in Unix commands – not too useful for me on a M$ box.

Frustration set it.

For 4 days.

What I didn’t include in those blocks were the following in italics, which I found on Experts Exchange:

<VirtualHost domain1.com:80>
ServerName domain1.com
DirectoryIndex index.html
DocumentRoot "E:/dir/to/my/www/files"
ServerAlias www.domain1.com

<Directory "E:/dir/to/my/www/files">
Allow from all
Order allow,deny
AllowOverride None
</Directory>


</VirtualHost>

This new block I included within each VirtualHost block of code allows the specified directory the specific permissions required for Apache to access and serve the files requested by the browser.

It should be mentioned now the particular order in which the VirtualHost directives were assigned for reference to the following issues I was experiencing: domain1.com, domain2.com and domain3.com respectively. Specifying this is helpful because after the inclusion of the permissions block of code in each of the directives, I was no longer receiving 403 errors. I was browsing, but only browsing domain3.com.

The way Apache reads the httpd.conf file is important to take note of: The web server reads the file from top to bottom, thusly showing only the content of the last VirtualHost directive, regardless of whether I was browsing domain1.com, WWW.domain1.com or any combination of the rest of the domains configured.

In ApacheConf, there is a “Test Configuration” routine of the httpd.conf file you are connected with and will output to a console window the contents if there are discrepancies.

[Thu Mar 29 20:10:04 2007] [warn] VirtualHost domain2.com:80 overlaps with Vir
tualHost domain3.com:80, the first has precedence, perhaps you need a Na
meVirtualHost directive
[Thu Mar 29 20:10:04 2007] [warn] VirtualHost domain1.com:80 overlaps with
VirtualHost domain2.com:80 , the first has precedence, perhaps you need a NameV
irtualHost directive
[Thu Mar 29 20:10:04 2007] [warn] NameVirtualHost *:80 has no VirtualHosts
Syntax OK
Press any key to continue . . .

The third [warn] level gave the MOST clues as the NameVirtualHost *:80 directive was the only one I had included in the httpd.conf file.

Easily enough, I change from:

NameVirtualHost *:80

to:

NameVirtualHost domain1.com:80
NameVirtualHost domain2.com:80
NameVirtualHost domain3.com:80

and wouldn’t you know it, they all resolve properly!

Woo hoo! I’ll be posting more about Apache and other OSI tools. I’m also going to start experimenting with Ubuntu and other Unix based O/S’s. Keep checking back for more!

Hail King Jesus!
(bs.)

flickr:pics

Camping with my Bride

Baptism 6

Baptism 5

Baptism 4

Baptism 3

Baptism 2

Baptism 1

6 mo pregnant

More Photos

Technorati

Add to Technorati Favorites
 
I just took the Style Compatibility Test on
Kaboodle.com. I want you to take it, too, so we
can see if we have similar taste & style.

Click here to take it now.
Fair Use Notice
This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: http://www.law.cornell.edu/uscode/17/107.shtml. If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.