locked
Exit Sub in an Update Panel RRS feed

  • Question

  • User-1312231374 posted

    This is with ASP.NET VB.  I use a message box and Exit Sub to stop a calculation with missing data.

    Public Sub MsgBox(ByVal Message As String)
    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf)
    System.Web.HttpContext.Current.Response.Write("alert(""" & Message & """)" & vbCrLf)
    System.Web.HttpContext.Current.Response.Write("</SCRIPT>")
    End Sub

    If Val(txtSalesPrice.Text) = 0 Or Val(txtIntRate.Text) = 0 Then
    MsgBox("Please enter a sales price and an interest rate.")
    Exit Sub
    End If

    This works until I add an Update Panel.  Then neither the message box or the Exit Sub work inside the Update Panel.  

    Any ideas about this?

    Thanks,

    Carthalion

    Thursday, February 26, 2015 1:33 PM

Answers

  • User753101303 posted

    Hi,

    An update panel just allows to get a page portion from the server and replace it client side. So you'll get client side the new content you sent back with this bu there is nothing that calls this JavaScript code.*

    To know why Exit Sub doesn't produce the effect you want we would need to know where it is. Exit Sub just exists the current method. The rest of the page is still rendered. Depending on what you replace here, an update panel may not be the best approach.

    If you want to keep the Update Panel approach you would have liekly to wrap this code Inside a js function and to call explicitely this function from your client side code when the panel has been retrieved (basically creating a kind of "onload" event for the panel rather than for the whole page).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 26, 2015 1:45 PM
  • User-1312231374 posted

    Great information.  Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 27, 2015 1:07 PM

All replies

  • User753101303 posted

    Hi,

    An update panel just allows to get a page portion from the server and replace it client side. So you'll get client side the new content you sent back with this bu there is nothing that calls this JavaScript code.*

    To know why Exit Sub doesn't produce the effect you want we would need to know where it is. Exit Sub just exists the current method. The rest of the page is still rendered. Depending on what you replace here, an update panel may not be the best approach.

    If you want to keep the Update Panel approach you would have liekly to wrap this code Inside a js function and to call explicitely this function from your client side code when the panel has been retrieved (basically creating a kind of "onload" event for the panel rather than for the whole page).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 26, 2015 1:45 PM
  • User-1312231374 posted

    Great information.  Thank you!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 27, 2015 1:07 PM