Wednesday, December 2, 2009

Adding HTML/Javascript block scripts

For quite a long time I wanted to know how could I include HTML / JavaScript / Visual Basic scripts (including their original editor colors) into my blog. I looked up on the internet for the answer finding nothing useful. Finally, I got this:

Somewhere I found that I needed a third party program that could do the translation job. This is the one I use now:

http://www.stevetrefethen.com/highlighter/default.aspx


However, there are also some others that I haven't try yet. You can find more information here:

http://stackoverflow.com/questions/557961/html-examples-syntax-highlighting-and-encoding-for-blog-posts

Tuesday, December 1, 2009

Identifying if a page is called from a popup

Situation:
I need to identify whether a page has been redirected from a popup window or it has been redirected from a full page, in order for me to perform a Redirect to "Main Menu" or "Close" from a button.

Solution:
1. Create two buttons (one that performs a PostBackUrl="/") and another one that executes (window.close() javascript event)

1 <asp:Button ID="cmdBackToMenu" runat="server" PostBackUrl="/" Text="Back to Main Menu" />
2 <asp:Button ID="cmdClose" runat="server" Text="Close" OnClientClick="window.close();"/>


2. Create a javascript event that will be called in the form.onload event.

1 <body bgcolor="#CCCCCC" onload="SettingButton();">



3. The javascript event should be able to identify whether a page was redirected from a popup window or from a full page and depending on the situation make visible or invisible the buttons created in the first step.

1 function SettingButton() {
2
3 if (opener) {
4 document.form1.cmdClose.style.visibility = "visible";
5 document.form1.cmdBackToMenu.style.visibility = "hidden";
6 }
7 else {
8 document.form1.cmdClose.style.visibility = "hidden";
9 document.form1.cmdBackToMenu.style.visibility = "visible";
10 }
11 }