Friday, April 11, 2008

Javascript onUnload and postback

So I just ran into an interesting scenario. I have a custom control where I need an event to fire before postback but I don't want to have to add an OnClientClick event in every page that uses the control. In fiddling with the javascript onunload event I found that oddly enough the unload event fires after postback to my aspx page. The solution? Use onbeforeunload instead:

window.onbeforeunload = unload;

function unload() {
alert("unload");
}

Wednesday, April 2, 2008

Asp Uploader Control Weirdness

It's been a while since my last post and I apologize for that, I need to post more often because I tend to run across interesting things to post about. I'm just lazy.

I ran into an issue the other day when working on a SharePoint site that had me confused for a while. For some reason when you access the Uploader.PostedFile.InputStream property twice (even when setting the Position in the file to zero manually upon setting up a new reference to it and wrapping things in a using statement) the second time you read it you’ll get an empty file. Which is fucked up.

Anyhow, I fixed that by accessing the Uploader.PostedFile.InputStream property in one of the instances where I wanted to access the file but didn't actually need an input stream. I haven’t really been able to make sense out of why it works this way but not the other but whatever. Life goes on.