title: javascript Error: 'return' statement outside of function when trying to disable a button on submit
body: <p>Am trying to re-use a function i got from one of the threads on this site. I want to disable an asp.net button when clicked such that a user does not click it several times.</p>
  
  <p>The button is inside an Ajax Updatepanel and also has a ConfirmButtonExtender, but when i click it, it get this javascript error in internet explorer. </p>
  
  <p>**</p>
  
  <blockquote>
    <p>Error: 'return' statement outside of
    function</p>
  </blockquote>
  
  <p>**</p>
  
  <p>When i remove the ConfirmButtonExtender, every thing works fine.</p>
  
  <p>Below is the function</p>
  
  <pre><code> Private Function DisableTheButton(pge As Control, btn As Control) As String
      Dim sb As New System.Text.StringBuilder()
      sb.Append("if (typeof(Page_ClientValidate) == 'function') {")
      sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
      sb.Append("if (confirm('Are you sure to proceed?') == false) { return false; } ")
      sb.Append("this.value = 'Please wait...';")
      sb.Append("this.disabled = true;")
      sb.Append(Page.ClientScript.GetPostBackEventReference(btn, ""))
      sb.Append(";")
      Return sb.ToString()
  End Function
  </code></pre>
  
  <p>And below is my page load</p>
  
  <pre><code> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      Me.btnSubmit.Attributes.Add("onclick", DisableTheButton(Me.Page, Me.btnSubmit))
  End Sub
  </code></pre>
  
  <p>Am also using the asp.net validation controls the button.</p>