Archive

Author Archive

An alternative way to do rollovers in javascript

Ok, this is more web design than .NET development, but I thought I’d share this tip. If you’re like me, you hate working with the highly complex table structure that gets generated when you press "Save for the web" in photoshop. You end up with little fine white lines cropping up between cells and ruining the look of your site.

Generally, when you have a button placed upon a background, you have to cut the image up into table cells, and then use an onMouseOver / onMouseOut attributes on the image to provide the rollover effect. But if you have 20 buttons on an image, placed irregularly on a background image, you end up with having to cut out 50 or so different cells with image fragments. And then it all becomes messy.

What I propose to to use a background image, and trap mouse movements over that image. when it falls within a particular window ie 20,20 to 30,30 – It overlays another image on top, providing a rollover effect (* Actually more of a ‘Hover’ effect, but quite similar), without having to cut up the image.

To give a sample of the javascript:

<script language="JavaScript">

var intRollovers = 2; 
var intSx = new Array; // start x (left)
var intEx = new Array; // end x (right)
var intSy = new Array; // start y (top)
var intEy = new Array; // end y (bottom)
var strImage =new Array; // Rollover image
var strLink =new Array; // hyperlink
var imgCache = new Array;

intSx[1]=224;intEx[1]=296;intSy[1]=88;intEy[1]=106;strImage[1]="ZoneDesign/HomeOn.gif";   strLink[1]="default.aspx";

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
if (!IE) document.captureEvents(Event.MOUSEDOWN)
document.onmousemove = getMouseXY;
document.onmousedown = getMouseXY;

function getMouseXY(e)
{
 if (IE)
 {
  tempX = event.clientX + document.body.scrollLeft;
  tempY = event.clientY + document.body.scrollTop;
 }
 else
 { 
  tempX = e.pageX;
  tempY = e.pageY;
 }   
 document.all["imgRollover"].style.display="none";
 for(i=1;i<intRollovers;i++)
 {
  if (tempX>intSx[i] &&
   tempX<intEx[i] &&
   tempY>intSy[i] &&
   tempY<intEy[i])
  {  
   document.all["imgRollover"].style.display="none";
   document.all["imgRollover"].style.left = intSx[i];
   document.all["imgRollover"].style.top = intSy[i];
   document.all["imgRollover"].src=strImage[i];
   document.all["imgRollover"].onload = unHideImage;   
   if ((IE && event.button == 1) || (!IE && e.which == 2))
   {
    window.location.href=strLink[i];
   }
   break;   
  }
 } 
 return true;
}

function unHideImage()
{
 document.all["imgRollover"].style.display="block";
}

</script>

Then include the following HTML after the body tag

<img id="imgRollover" style="position:absolute; display:none">

Categories: Uncategorized

IIS worker process isolation mode

I found my IIS server crashing more often than usual, and although a net stop w3svc / net start w3svc was bringing it up to speed again. I couldn’t rely on this to keep the server going on a long-term basis

I looked in the Event log, and found a recurring error which read "It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.". As readers of this blog will know I have .NET 2.0 beta 2 installed on my server, along with .NET 1.1. So I read up on the Microsoft Technet site about IIS worker processes, and it seemed to recommend this course of action

* Create a new Application Pool specifically for .NET 2.0 apps.

* Right click on a .NET 2.0 website (in my case www.downloadsoft-ware.co.uk) click on Home directory. Then under the drop down box for application pools, select the .NET 2.0 app-pool.

And it hasn’t crashed since. But I’ll leave it for 24 hours.

 

 

Categories: Uncategorized

Speed typing challange

Categories: Uncategorized

WSDL doesn’t work on non standard ports

If you try to make a web reference to a web service that resides on a non-standard port (i.e. not port 80), you get an error "Unable to download files from …. Do you want to skip these files and continue?"

You get an error if you try to update the reference

Custom tool warning: DiscoCodeGenerator unable to initialize code generator.  No code generated.

The reference.map file contains the following

<DiscoveryClientResultsFile xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;

<Results>

<DiscoveryClientResult referenceType="System.Web.Services.Discovery.DiscoveryDocumentReference" url="http://www.someurl.com:809/whatever.asmx?disco&quot; filename="whatever.disco" />

</Results>

</DiscoveryClientResultsFile>

Trying to add a reference manually using WSDL gets the following error

Microsoft (R) Web Services Description Language Utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Warning: no classes were generated.

I worked around the bug, but hopefully word will get out to the Microsoft developers in charge of WSDL.exe to fix this bug.

Fiach,

http://network.programming-in.net

"I before E except after C – Reinvention Being Weighty Science"

Categories: Uncategorized

Using OleDb with Excel

Being an advocate of OleDb, I thought I’d share some information I learnt tonight regarding connecting to Excel spreadsheets using OleDb. Using a DSN such  as Provider=Microsoft.Jet.OLEDB.4.0;Data Source=<filename>;&Extended Properties="Excel 8.0;" you get access to the spreadsheet "tables" as if it was an access database.

A few points I noticed. was that sheets are named [sheet1$], column headers may not always be named, so you may need to resort to using ordinals in your recordset. Also, when doing "LIKE" clauses in sql, you use the % syntax, not the * syntax, as common with MS Access.

 

Categories: Uncategorized

Change .NET versions on the fly with the IIS snap in.

I had found with ASP.NET 2.0 beta 1, that it converted all my websites hosted on my server to .NET 2.0 – even though they were developed in .NET 1.1, this didn’t cause too many problems, since .NET 2.0 is very much backwards compatible with .NET 1.1. After installing .NET 2.0 beta 2, it reverted all my websites back to .NET 1.1, even though some were developed in .NET 2.0, thus crashing some websites, such as www.downloadsoft-ware.co.uk 

There is the IIS MMC snap in that is supposed to toggle versions, (under properties / ASP.NET) but it never worked under Beta 1, and in Beta 2, it was nowhere to be seen!

After hunting on the web for a solution, I found this blog http://dotnet.org.za/ahmeds/archive/2005/04/26/19028.aspx?Pending=true which recomended "Microsoft comments: If a previous version was not uninstalled correctly, please regedit eliminate all versions except 2.0.0.0 in the following locations:
HKEY_CLASSES_ROOTCLSID{7D23CCC6-A390-406E-AB67-2F8B7558F6F6}InprocServer32
HKEY_CLASSES_ROOTCLSID{FD5CD8B1-6FE0-44F3-BBFB-65E3655B096E} InprocServer32
HKEY_CLASSES_ROOTCLSID{FEDB2179-2335-48F0-AA28-5CDA35A2B36D}InprocServer32"

I did this, and the website crashed with a "Server Application unavailable". I rebooted the server, toggled the site back to .NET 1.1 then back to .NET 2.0 and it worked!

Categories: Uncategorized

OleDB access for SQL server 2005

After upgrading my server from ASP.NET 2.0 Beta 1 to ASP.NET 2.0 beta 2, I found, to my horror, it could no longer connect to my SQL server 2005 database – with an "Access is denied" error.

However, I found out that I can use an OLEDB connection string thus

Provider=SQLNCLI.1;
Integrated Security=SSPI;
Persist Security Info=False;
Initial Catalog=<your database>;
Data Source=.SQLEXPRESS;
Use Procedure for Prepare=1;
Auto Translate=True;
Packet Size=4096;
Use Encryption for Data=False;
Tag with column collation when possible=False;
MARS Connection=True;
DataTypeCompatibility=0

— Not the prettiest thing in the world, but it works!

http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic13589.aspx

 

 

Categories: Uncategorized

Unzipping GZIP files on the fly (C#)

I recently set about writing some code to download a file named pf[1].csv.gz – which was GZIP’ed and creating the corresponding CSV file on disk. Using the ICSharpCode Zip compression library, I used this code:

string strCSVFile = "c:\pf[1].csv";
string strUrl = "http://www.someurl.com/pf[1].csv.gz";
WebClient wc =
new WebClient();
Byte[] bZip = wc.DownloadData(strUrl);
MemoryStream msZip =
new MemoryStream(bZip);
GZipInputStream gzisZip =
new GZipInputStream(msZip);
FileStream fsOutput =
new FileStream(strCSVFile,FileMode.Create);
Byte[] bCSV =
new Byte[Byte.MaxValue];
Int32 iReadCount = Byte.MaxValue;
while(iReadCount>0)
{
   iReadCount = gzisZip.Read(bCSV,0,iReadCount);
   fsOutput.Write(bCSV,0,iReadCount);
}
fsOutput.Close();
gzisZip.Close();

Categories: Uncategorized

Printer friendly CSS

A tip I just learned this morning, if you need a website to appear different when it prints, you can add a CSS style that is only applied during printing. – For instance, if you wanted to strip off menus, or remove certain graphics, you could use display:none in the printer css style.

The trick to it is to use this format to include your CSS

<style type="text/css" media="screen">@import "screen.css";</style>
<style type="text/css" media="print">@import "print.css";</style>

On a personal note, I just noticed that one of my domains has either not been listed or removed from google http://www.listofestateagents.info, which was a bit of a pity. For some reason over the last week my Page impressions have gone down, but my CTR has gone up. Net result being that revenue took a hit. But I guess that means that at least google is targeting my pages better.

 

Categories: Uncategorized

ASP.NET chatroom with out of band calls.

Chatrooms are typically developed in Flash or java, since they both contain the facility to make HTTP requests to the server from which the Applet / SWF was downloaded from. An ActiveX control named Microsoft.XMLHTTP also has the same capability, and is capable of running on browsers with default security settings (I believe it may be marked ‘safe for scripting’). I also believe that it is compatible with FireFox, and IE7 are relaxing security for this specific control.

So, I decided to put together a simple chatroom example in asp.net using this technology. Based on an excellent example by Dino Esposito.

Starting off with a simple html form thus:

<form runat="server">
   <h1>Demonstrate Simple chatroom with Out-of-band Calls</h1>
   <hr>
   Message: <input type="text" name="txtMessage">
   <Button Runat="server" ID="ButtonGo">Send & Receive</Button>
   <hr>
   <span ID="Msg" />
  </form>

and some associated javascript:

<SCRIPT language="javascript">
    setTimeout("Callback(”)",2000);
 function DoCallback(url, params)
    {
  var pageUrl = url + "?callback=true&param=" + params;
  var xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
  xmlRequest.open("POST", pageUrl, false);
        xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlRequest.send(null);
        return xmlRequest;
    }
   
    function Callback(message)
    {
  var xmlRequest = DoCallback("callback.aspx", message);  
  Msg.innerHTML = xmlRequest.responseText;
     if (message==”) setTimeout("Callback(”)",2000);
    }
</SCRIPT>

As we can see, a post request is sent back to callback.aspx, which handles the request thus:

<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
 if (Request.QueryString["callback"] != null)
 {
  string param = Request.QueryString["param"].ToString();
  Response.Write(RaiseCallbackEvent(param));
  Response.Flush();
  Response.End();  
 }
 else
 {
  string callbackRef = "Callback(document.all[‘txtMessage’].value)";
  ButtonGo.Attributes["onclick"] = callbackRef;
 }
}

 string RaiseCallbackEvent(string eventArgument)
 {
  if (eventArgument!="")
  {
   Application["conversation"] += eventArgument + "<br>";
  }
  return Application["conversation"].ToString();
 }
 
</script>

Pretty simple. To check out a demo see www.globefinder.info/callback.aspx

 

 

 

Categories: Uncategorized