Posts

Showing posts from August, 2004

Replace content in database table (SQL)

You may have rows in your database that contains <br>, which you want to replace with line breaks (this may be the case if you are using Server.HtmlEncode to encode your output, which you didn't previously do). This can simply be done using the replace function (note the line break): UPDATE [table] SET [column]= REPLACE([column], '<br>', ' ') WHERE [column] LIKE '%<br>%' Also, if you wish to convert < and > to their html encoded equivalents: UPDATE [table] SET [column]= REPLACE([column], '<', '&lt;') WHERE [column] LIKE '%<%' UPDATE [table] SET [column]= REPLACE([column], '>', '&gt;') WHERE [column] LIKE '%>%' Or to do the reverse: UPDATE [table] SET [column]= REPLACE([column], '&lt;', '<') WHERE [column] LIKE '%&lt;%' UPDATE [table] SET [column]= REPLACE([column], '&gt;',

Popup Window Countdown (JavaScript)

This code opens a new popup window that contains a timer that counts down, then closes the window when it reaches 0. Will not work if user has a popup blocker blocking the page. <html> <head> <title>Popup Timer</title> <script language="JavaScript" type="text/JavaScript"> // popup window var var popup; // At what number shall the countdown counter start? CounterStart = 10; // This function CustomAction() can be modified to do // whatever you want done every second. function CustomAction() { popup.document.timer.timeleft.value = CounterStart; } // end of function CustomAction() // end of JavaScript customization function Decrement() { CounterStart--; CustomAction(); if(CounterStart <= 0) { popup.close(); alert('Timer reached 0'); } else { setTimeout('Decrement()',1000); } } function StartTheCounter() { openPopup(120,100); setTimeout('Decrement()',1000); } f

Prevent User Control Code from running (ASP.NET)

You can prevent code within a user control (ascx file) from running if it is invisible on the containing page. To do so, just check base.Visible (C#) or MyBase.Visible (VB). For example: C# private void Page_Load(object sender, EventArgs e) { if (base.Visible) { // run code } } VB Private Sub Page_Load(sender As Object, e As EventArgs) If MyBase.Visible Then ' run code End If End Sub

Recursive File List Control (ASP.NET)

This control lists files and folders within a given directory. It shows only the root directories and files, but if you click a folder in the list, your get the sub folders and files. Control code (filelist.ascx) <%@ Control Language="C#" %> <%@ Import Namespace="System.Collections" %> <script runat="server"> private void Page_Load(object sender, EventArgs e) { // add file types fileTypes.Add("doc"); fileTypes.Add("rtf"); fileTypes.Add("xls"); fileTypes.Add("pdf"); walkFolders(VirtualFolder); lnkReset.NavigateUrl = Url; } public string VirtualFolder = "/"; private ArrayList fileTypes = new ArrayList(); private ArrayList folders; private ArrayList Folders { get { if (folders==null) { if (PathInfo!=null) { folders = new ArrayList(PathInfo.Split(';')); } else { folders = new ArrayList(); } } return folders; } set { f

Internet Explorer Toolbar Fix

When Internet Explorer has several toolbars installed, the context menu items do not reflect the correct toolbar - i.e. Google and Yahoo toolbars are both showing and you wish to hide the Google one. So you click 'Google' in the menu - but the Yahoo one disappears instead. This bug has been around for a long time. However, it can be fixed by tweaking the registry (found at http://www.mvps.org/winhelp2002/ietips.htm#Odd ). Here is the fix (create blank text file called ResetBrowserToolbar.reg , and then double-click the newly created file) REGEDIT4 [HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Toolbar\WebBrowser] "ITBarLayout"=-