joeybagadonutz Posted December 17, 2003 Posted December 17, 2003 Hi, I do this all the time for windows forms, and I put this code into the code behind for web forms and I get no errors, but it doesnt work, is there a way to do a try catch for asp.net web forms? I use vb.net code behind, thanks! Try Cmd.ExecuteNonQuery() Catch ex As Exception MsgBox("Error: " & ex.message) End Try Quote
Moderators Robby Posted December 17, 2003 Moderators Posted December 17, 2003 What part you you talking about, th message box? you cannot display a msgbox from the server. I prefer to place those types of messages in a label or a literal control. Quote Visit...Bassic Software
sergeromero Posted December 19, 2003 Posted December 19, 2003 Hey, Try the following: Catch ex As Exception Dim strErrorMessage As String strErrorMessage = ex.Message.ToCharArray strErrorMessage = strErrorMessage.Replace(Chr(13), "\n") strErrorMessage = trErrorMessage.Replace(Chr(10), "\n") strErrorMessage = trErrorMessage.Replace("'", " ") strErrorMessage = trErrorMessage.Replace("""", " ") Response.Write("<script language='JavaScript'>") Response.Write("alert('" & trErrorMessage & "');") Response.Write("</script>") End Try The "Replace" statements take away any carriage returns, single, and double quotes that come within the Message property of the Exception, and that might make the JavaScript code to fail. Hope this helps. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.