esposito
Centurion
Hello, I have found some special code that allows you to simulate the VB.NET ShowMessage method in ASP.NET. This code runs as follows:
What is great in the code above is that you can call the alert box at any time in your routines. This is much better than another solution I found which relies on the "Attributes.Add" method.
The problem with the latter is that, if you add the onClick attribute to the button, the alert box is triggered as soon as the button is clicked. So, there's no way you can prompt the user with the alert box only if a particular condition occurs.
That's why I believe that the above mentioned ShowMessage sub is the best solution for the creation of message boxes in ASP.NET. Unfortunately, there are two little problems that I would like you to help me sort out.
The first is, when I click on the button, all the objects on the page become invisible as soon as the message box appears. After I click on "OK" in the alert box, they appear again! Although this "bug" does not prevent your Web page from working correctly, it is not professional to see, so I would very much like to get rid of it.
The second problem I have encountered is, I can't go to a new line in the message I put in the alert box! In other words, the code below does not work: (please try to believe)
Can anybody give me a helping hand with the code above?
TIA
Code:
Public Sub ShowMessage(ByVal strMessage As String)
Dim strScript As String
strScript = "<script language=javascript> " & Environment.NewLine
strScript = strScript + "alert('" & strMessage & "')"
strScript = strScript + "<"
strScript = strScript + "/"
strScript = strScript + "script>"
RegisterClientScriptBlock("clientScript", strScript)
End Sub
Sub btnMsgBox_Click(sender As Object, e As EventArgs)
ShowMessage("This alert box has been created with Javascript code.")
End Sub
What is great in the code above is that you can call the alert box at any time in your routines. This is much better than another solution I found which relies on the "Attributes.Add" method.
The problem with the latter is that, if you add the onClick attribute to the button, the alert box is triggered as soon as the button is clicked. So, there's no way you can prompt the user with the alert box only if a particular condition occurs.
That's why I believe that the above mentioned ShowMessage sub is the best solution for the creation of message boxes in ASP.NET. Unfortunately, there are two little problems that I would like you to help me sort out.
The first is, when I click on the button, all the objects on the page become invisible as soon as the message box appears. After I click on "OK" in the alert box, they appear again! Although this "bug" does not prevent your Web page from working correctly, it is not professional to see, so I would very much like to get rid of it.
The second problem I have encountered is, I can't go to a new line in the message I put in the alert box! In other words, the code below does not work: (please try to believe)
Code:
Public Sub ShowMessage(ByVal strMessage As String)
'Same code as above...
End Sub
Sub btnMsgBox_Click(sender As Object, e As EventArgs)
ShowMessage("This is the first line." & ControlChars.NewLine & "And this should be the second.")
End Sub
Can anybody give me a helping hand with the code above?
TIA