try
Catch ex As Exception
If Err.Number <> 0 Then msgbox(ex.Message, MsgBoxStyle.Critical)
Exit Sub
End Try
its work fine But i want to show this with ajax like this.
try
Catch ex As Exception
If Err.Number <> 0 Then DisplayAJAXMessage(Me, ex.Message.ToString)
Exit Sub
End Try
Sub DisplayAJAXMessage(ByVal page As Control, ByRef Message As String)
Dim myScript As String = ("alert('" & Message & "');")
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, True)
End Sub
But its Not working. tell me what is the problem of this code. Please Help
it was looking right code but i have try this and also check with break point. its running right But message did not display in application. You can check it.
i was paste my aspx code in my first post. its my Code and when i use it in simple message then it works fine. for example.
Sub DisplayAJAXMessage(ByVal page As Control, ByRef Message As String)
Dim myScript As String = ("alert('" & Message & "');")
ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, True)
End Sub
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
DisplayAJAXMessage(cmdUpdate, "My Message")
end sub
But when i use this code it do not work. and no one error comes.
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Try
UpdateTable("Update BankDetail set AccountNo='" & txtAccountNo.Text & "' , " & _
"Cno='" & txtBankCNo.Text & "', " & _
"AccountID='" & cmbAccountID2.Text & "', " & _
"BankName='" & txtBankName.Text & "', " & _
"BankAddress='" & txtBankAddress.Text & "', " & _
"City='" & txtCity.Text & "', " & _
"ShortName='" & txtShortName.Text & "' where BNo='" & txtUpdate.Text & "'")
Catch ex As Exception
If Err.Number <> 0 Then DisplayAJAXMessage(cmdUpdate, ex.Message.ToString)
Exit Sub
End Try
End Sub
Public Function UpdateTable(ByVal Query As String)
With obj
.cn = GetConnection()
.comm.CommandText = ""
.comm.Connection = .cn
.comm.CommandType = Data.CommandType.Text
.comm.CommandText = Query
.comm.CommandTimeout = 0
.comm.ExecuteNonQuery()
.cn.Close()
End With
End Function
means if you are using static message its working and if you are using ex.Message its not working?? may be you can check your ex.Messge in debug mode and make sure its not containing any
' single quotatin mark(')
NewProgramer
Member
391 Points
232 Posts
Error message Problem
Nov 19, 2011 02:43 AM|LINK
hi
try Catch ex As Exception If Err.Number <> 0 Then msgbox(ex.Message, MsgBoxStyle.Critical) Exit Sub End Tryits work fine But i want to show this with ajax like this.
try Catch ex As Exception If Err.Number <> 0 Then DisplayAJAXMessage(Me, ex.Message.ToString) Exit Sub End Try Sub DisplayAJAXMessage(ByVal page As Control, ByRef Message As String) Dim myScript As String = ("alert('" & Message & "');") ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, True) End SubBut its Not working. tell me what is the problem of this code. Please Help
patricgreat
Participant
983 Points
278 Posts
Re: Error message Problem
Nov 19, 2011 03:18 AM|LINK
its looking perfect but still try using a different control(instead of page) which is inside updatepanel instead of page.
ScriptManager.RegisterStartupScript(control, control.GetType(), "MyScript", myScript, True)
NewProgramer
Member
391 Points
232 Posts
Re: Error message Problem
Nov 19, 2011 03:33 AM|LINK
thanks but sory to say i could'nt understand. can you explain through code or some example?
patricgreat
Participant
983 Points
278 Posts
Re: Error message Problem
Nov 19, 2011 03:44 AM|LINK
ok, this is just my thought :) i am not sure if it will work or not but please make a try :)
you must be using updatepanel in your aspx page. lets assume that you have some button name myControl inside updatepanel.
try
Catch ex As Exception
If Err.Number <> 0 Then DisplayAJAXMessage(myControl, ex.Message.ToString)
Exit Sub
End Try
Sub DisplayAJAXMessage(ByVal myCon As Button, ByRef Message As String)
Dim myScript As String = ("alert('" & Message & "');")
ScriptManager.RegisterStartupScript(myCon,myCon.GetType(), "MyScript", myScript, True)
End Sub
NewProgramer
Member
391 Points
232 Posts
Re: Error message Problem
Nov 19, 2011 04:03 AM|LINK
it was looking right code but i have try this and also check with break point. its running right But message did not display in application. You can check it.
patricgreat
Participant
983 Points
278 Posts
Re: Error message Problem
Nov 19, 2011 11:38 AM|LINK
if possible can you please paste your aspx code? how r u using ajax?
NewProgramer
Member
391 Points
232 Posts
Re: Error message Problem
Nov 21, 2011 02:42 AM|LINK
i was paste my aspx code in my first post. its my Code and when i use it in simple message then it works fine. for example.
Sub DisplayAJAXMessage(ByVal page As Control, ByRef Message As String) Dim myScript As String = ("alert('" & Message & "');") ScriptManager.RegisterStartupScript(page, page.GetType(), "MyScript", myScript, True) End Sub Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) DisplayAJAXMessage(cmdUpdate, "My Message") end subBut when i use this code it do not work. and no one error comes.
Protected Sub cmdUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Try UpdateTable("Update BankDetail set AccountNo='" & txtAccountNo.Text & "' , " & _ "Cno='" & txtBankCNo.Text & "', " & _ "AccountID='" & cmbAccountID2.Text & "', " & _ "BankName='" & txtBankName.Text & "', " & _ "BankAddress='" & txtBankAddress.Text & "', " & _ "City='" & txtCity.Text & "', " & _ "ShortName='" & txtShortName.Text & "' where BNo='" & txtUpdate.Text & "'") Catch ex As Exception If Err.Number <> 0 Then DisplayAJAXMessage(cmdUpdate, ex.Message.ToString) Exit Sub End TryPublic Function UpdateTable(ByVal Query As String) With obj .cn = GetConnection() .comm.CommandText = "" .comm.Connection = .cn .comm.CommandType = Data.CommandType.Text .comm.CommandText = Query .comm.CommandTimeout = 0 .comm.ExecuteNonQuery() .cn.Close() End With End FunctionNewProgramer
Member
391 Points
232 Posts
Re: Error message Problem
Nov 21, 2011 03:19 AM|LINK
and i also want to explane that when i use this code.
Catch ex As Exception If Err.Number <> 0 Then DisplayAJAXMessage(cmdUpdate, ex.Message.ToString) Exit Sub End Tryit doesn't work. no message display in run time. But when i use this
Catch ex As Exception If Err.Number <> 0 Then DisplayAJAXMessage(cmdUpdate, "any Message") Exit Sub End Trythen its work perfect.
patricgreat
Participant
983 Points
278 Posts
Re: Error message Problem
Nov 21, 2011 03:48 AM|LINK
means if you are using static message its working and if you are using ex.Message its not working?? may be you can check your ex.Messge in debug mode and make sure its not containing any ' single quotatin mark(')
NewProgramer
Member
391 Points
232 Posts
Re: Error message Problem
Nov 21, 2011 05:43 AM|LINK
yes when i debug that code ex.message display. But in web page it does not display.