Search code examples
asp.netvb.netmsgbox

MsgBox doesn't work after deployment


I've deployed my ASP.NET application today. It's a web application (I am using forms, etc.). I was happy with all my functionalities. For example, I had part of the of the code that says

if c.results = " " then MsgBox("Error! No record was returned)

Then I clear all my text boxes.

That MsgBox was working when I was running my application locally, but now that I've deployed it I get a server run error! I read some similar posts that said MsgBox is not supported with web applications, but all their answers were with JavaScript. I am not familiar with it, but I don't understand how to put my JavaScript in my Visual Basic class instead of where I am calling the MsgBox- is there a way fixing the above issue with VB.NET code?

Here is the code:

Dim results = customer.getCustomerDetails(txtCustomerNumber.Text, txtDOB.Text)

If (results.customerNumber = "") Then
    Response.Write("<script>alert('Customer record not found')</script>")

    txtCustomerNumber.Text = ""
    txtDOB.Text = ""

Else
    ( Do the other stuff)

End if

Solution

  • MsgBox is server side so it can't show up to the client which is only seeing the client side of the ASP.NET webform, hence use the following if you want to access a JavaScript alert from code behind or simply alert in JavaScript:

    Page.ClientScript.RegisterStartupScript(Page.GetType(), "alert", "<script 
    language=JavaScript>alert('your wanted message');</script>")