Click here to Skip to main content
14,272,574 members
Rate this:
Please Sign up or sign in to vote.
I am trying to show a alert box for an error.

Here is the part of the code:

Catch ex As Exception
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ExceptionMessage_AuditMain4", "<script type='text/JavaScript'>alert( '" + ex.Message + "');</script>", True)
Finally



But it doesn't display the alert message. The message is being called from a selected index change of a dropdownlist with autopostback enabled

Page has ajax update panels and I have step through the code to ensure the block is being tripped (executed).
Posted
Updated 28-Jan-12 21:52pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

Using a partial page update, such with an UpdatePanel, you are not getting the full page life cycle and the script is not being injected into the response stream.

A more common approach is to pass the information back to the client via the javascript callback function and display any error messages there.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Catch ex As Exception
dim msg as string=ex.message
    page.RegisterScriptblock( Me.GetType(), "alert ","alert("' & msg & '"), True)
Finally
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100