how can I make the button_click to execute first before the script that I added in the buttons's attribute

VB Code:
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         'Put user code to initialize the page here
  3.  
  4.         Dim scriptOk As String
  5.         scriptOk = "window.returnValue = true; " _
  6.         & " window.dialogArguments.strName = window.document.all.MyFile.value; " _
  7.         & " window.close();"
  8.         btnOk.Attributes.Add("onclick", scriptOk)
  9.         btnCancel.Attributes.Add("onclick", "window.returnValue = false;window.close();")
  10.     End Sub
  11.  
  12. Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
  13.         'Response.Write("hello")
  14.         'MyFile.PostedFile.SaveAs("")
  15.  
  16.     End Sub

myFile is an htmlinputfile server control, I want the file to be uploaded first before the web page execute the script to close the window

Thanks,

Jewel