Tuesday, October 27, 2009

Nested Master Pages

I have two master pages, one that uses a two column layout, and one that uses a three column layout. So instead of duplicating the entire file (ASP.NET file tags, XML file tags, script tags, css link tags, header and footer controls, etc) I did some googling and discovered that you can build master pages from a base master page (the derived master pages = nested master pages), much like you can create a base ASPX page and use the content place holder control as a template to vary the content. Yay!

One important detail though, is that the nested master pages need to inherit either from the vanilla master page class or a custom master page class (not the base master page class!!!), and the base master page should inherit from the vanilla master page class or a custom master page class

http://msdn.microsoft.com/en-us/library/x2b3ktt7.aspx

This is the parent master file:
<% @ Master Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="Form1" runat="server">
<div>
<h2>Parent Master</h2>
<p style="font:color=red">This is parent master content.</p>
<asp:ContentPlaceHolder ID="MainContent" runat="server" />
</div>
</form>
</body>
</html>

This is the child master file:

<%@ Master Language="C#" MasterPageFile="~/Parent.master"%>
<asp:Content id="Content1" ContentPlaceholderID="MainContent" runat="server">
<asp:panel runat="server" id="panelMain" backcolor="lightyellow">
<h2>Child master</h2>
<asp:panel runat="server" id="panel1" backcolor="lightblue">
<p>This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent1" runat="server" />
</asp:panel>
<asp:panel runat="server" id="panel2" backcolor="pink">
<p>This is child master content.</p>
<asp:ContentPlaceHolder ID="ChildContent2" runat="server" />
</asp:panel>
<br />
</asp:panel>
</asp:Content>

And finally, regular page that references the child master file:

<%@ Page Language="C#" MasterPageFile="~/Child.master"%>
<asp:Content id="Content1" ContentPlaceholderID="ChildContent1" runat="server">
<asp:Label runat="server" id="Label1"
text="Child label1" font-bold="true" />
<br />
</asp:Content>
<asp:Content id="Content2" ContentPlaceholderID="ChildContent2" runat="server">
<asp:Label runat="server" id="Label2"
text="Child label2" font-bold="true"/>
</asp:Content>

Friday, October 23, 2009

Hipster: The Dead End of Western Civilization

We are a lost generation, desperately clinging to anything that feels real, but too afraid to become it ourselves.

awesomely simple explanation of javascript:void(0)

http://www.tizag.com/javascriptT/javascriptvoid.php

JavaScript Void 0

Hyperlinks like this one entice visitors to click because they know clicking it will lead them to a new page. However, sometimes when you are making a script, you would like to add functionality to your website that lets a hyperlink to be clicked and perform a useful action like update the sums on the webpage, without loading a new page.


It's these types of programming solutions that will utilize the JavaScript Void 0 programming tool. This lesson will teach you some of the reasons to use the JavaScript Void 0programming strategy in your scripts.



Directly Executing JavaScript in a Browser

Web browsers allow you to execute JavaScript statements directly by entering JavaScript code into the browser's URL text field. All you need to do is place a JavaScript: before your code to inform the browser you wish to run JavaScript. You can play around with this right now by typing something like



  • JavaScript:alert("I'm learning at Tizag.com")

into the browser's URL text field and pressing Enter.



This is useful to you, the JavaScript scripter, because you can now set your hyperlinks's href attribute equal to a JavaScript statement! This means you can remove the hyperlink's ability to load a new page and reprogram it to do your "complete some actions directly on this page" bidding.


This practice can be seen in services like Gmail (Google Email) which does a great deal of interaction with hyperlinks, but has very few new pages loading. Here is an example link that does not load a new webpage.



JavaScript Code:

<a href="javascript: alert('News Flash!')">News Flash</a>

Display:

This is interesting to learn, but it isn't much more than a gimmick. The true power of direct URL JavaScript statements is only unleashed when you use it to return a value. This is where void 0 comes into play.



JavaScript Void 0 Explanation

Web browsers will try and take whatever is used as a URL and load it. The only reason we can use a JavaScript Alert statement without loading a new page is because alert is a
function that returns a null value. This means that when the browser attempts to load a new page it sees null and has nothing to load.


The important thing to notice here is that if you ever do use a JavaScript statement as the URL that returns a value, the browser will attempt to load a page. To prevent this unwanted action, you need to use the void function on such statement, which will always return null and never load a new page.



Simple JavaScript Void 0 Simple Example

void is an operator that is used to return a null value so the browser will not be able to load a new page. An important thing to note about the void operator is that it requires a value and cannot be used by itself. Here is a simple way to use void to cancel out the page load.



JavaScript Code:

<a href="javascript: void(0)">I am a useless link</a>

Display:

Simple JavaScript Void 0 Useful Example

This example shows how you would return a value using the void operator. myNum is a variable that we set to the value 10. We then use the same variable myNum in an alertoperation.



JavaScript Code:

<a href="javascript: void(myNum=10);alert('myNum = '+myNum)">
Set myNum Please</a>

Display:

Tuesday, October 20, 2009

Friday, October 16, 2009

fixed my IIS "page not found error"

My local development environment uses IIS7, which has a different interface for managing HTTP handler mappings, and which uses different web.config settings to detect those mappings from IIS6. Some pages on the site require URL path rewriting to load pages that live in a non-root directory, but give the user the ability to navigate to them by creating the illusion that they live in the root directory. But the same site on a staging server using IIS6 was resulting in a page not found error. Because the error was happening before IIS could serve up the custom 404 page, the error was suspected to be a missing or bad setting in IIS.

Although this solution wasn't voted the highest or as "the answer" to the OP's question, it seemed to fix the problem and get rid of the error!

"If I understand the problem correctly, it sounds like you need add a "Wildcard Application Mapping" for your virtual directory. In other words, you want to forward all requests to any file extension to ASP.NET's ISAPI extension.

To do so, open the properties of your virtual directory. On the Virtual Directory tab (Home Directory tab if it's a web site), click the Configuration... button. Click the Insert... button next to the bottom list box in the dialog that shows up. In this dialog, choose "%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" as the executable and make sure to un-check "Verify that file exists" checkbox, since the files to be requested don't live in your virtual directory."

Thursday, October 15, 2009

Things to post about:

Using USPS Web Tools
Learning just enough XQuery to query XML data from a SQL Server database

Thursday, October 8, 2009

ASP.NET Ajax Web Services [ScriptMethod(UseHttpGet = true)]

HTTP POST Is Slower than HTTP GET, but It Is Default in ASP.NET Ajax

ASP.NET Ajax, by default, makes HTTP POST for all web service calls. HTTP POST is more expensive than HTTP GET. It transmits more bytes over the wire, thus taking precious network time, and it also makes ASP.NET do extra processing on the server end. So, you should use HTTP GET as much as possible. However, HTTP GET does not allow you to pass objects as parameters. You can pass numerics, strings and dates only. When you make an HTTP GET call, Atlas builds an encoded URL and makes a hit to that URL. So, you must not pass too much content that makes the URL become larger than 2048 characters. As far as I know, that's the max length of any URL. In order to enable HTTP GET on a web service method, you need to decorate the method with the [ScriptMethod(UseHttpGet=true)] attribute:

[WebMethod] [ScriptMethod(UseHttpGet=true)] 
public string HelloWorld()
{
}

Wednesday, October 7, 2009

DZone The heart of the Java development community

I'm following DZone on Twitter after getting an email today from a grad student at Delaware I worked with as an undergrad the summer I did research. He's contributed a few articles, and even though I don't code in Java on a daily basis, I did come across a different article that raised some good questions about what it means to be a software developer, and specifically, what responsibility comes along with the "developer" part of that, Staying Current: A Software Developer's Responbility. Two questions that he asks (and looks for in potential teammates) really stuck out to me:

* What language(s) that are gaining popularity, but not yet mainstream, have you written Hello World in?
* Do you read books or blogs looking for new ideas at least (on average) once every two weeks?

I've discovered for myself that the idea behind the first question is an essential part of the job, and that discovery on a daily basis is key to learning "Hello World" knowledge about new stuff. Although I haven't actually written Hello World in a new language, there are definitely basic things I've learned everyday about new technologies I didn't/don't know anything about, but which help to nudge the door open and keep it open for them. But I've definitely realized the benefit of examining a problem thoroughly, perhaps even excessively, if there's something in it for me, especially if it concerns something in particular that's in my blind spot as a gap in my knowledge; its crucial that I'm assertive about honing any missing fundamental knowledge, and even more crucial about gaining new knowledge.