OnUnload is a server side event. It is called when the control unloads from memory on the server. You can't use it to call a JavaScript function.
I think your misunderstanding comes from the difference between server side and client side. In web frameworks, your server side code executes first and renders HTML (along with CSS and JavaScript). That's all sent to the client where it is then executed in the browser.
If you want to have the user confirm before they navigate away from the page, you need to add an event handler from the appropriate event on the client side. Like this:
window.onbeforeunload = function() {
// Do something
}
See this question for more detail.
Keep in mind that you should not abuse this capability by asking them on every page. You typically only do this if there is important page state, such as the user has partially filled out a form.