locked
Error message Problem RRS feed

  • Question

  • User988538322 posted

    hi

    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

    Friday, November 18, 2011 10:43 PM

All replies

  • User1042132515 posted

    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)

    Friday, November 18, 2011 11:18 PM
  • User988538322 posted

    thanks but sory to say i could'nt understand. can you explain through code or some example?

    Friday, November 18, 2011 11:33 PM
  • User1042132515 posted

    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

     

    Friday, November 18, 2011 11:44 PM
  • User988538322 posted

    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. 

    Saturday, November 19, 2011 12:03 AM
  • User1042132515 posted

    if possible can you please paste your aspx code? how r u using ajax?

    Saturday, November 19, 2011 7:38 AM
  • User988538322 posted

    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 
    Sunday, November 20, 2011 10:42 PM
  • User988538322 posted

    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 Try

    it 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 Try

    then its work perfect. 

    Sunday, November 20, 2011 11:19 PM
  • User1042132515 posted

    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(')

    Sunday, November 20, 2011 11:48 PM
  • User988538322 posted

    yes when i debug that code ex.message display. But in web page it does not display. 

    Monday, November 21, 2011 1:43 AM
  • User1042132515 posted

    can you paste that message? or just check if there are any single quotation mark is there?

    Monday, November 21, 2011 1:59 AM
  • User988538322 posted

    Conversion failed when converting the varchar value 'Select Record' to data type int.

    Monday, November 21, 2011 2:20 AM
  • User1042132515 posted

    the single quotation mark ' is creating issue. please try ex.messge.tostring().replace("'","")

    Monday, November 21, 2011 3:16 AM
  • User988538322 posted

    Still its not working. if you want i can send you a vedio where you can understand Easily.

    Monday, November 21, 2011 3:29 AM
  • User1042132515 posted

    are you sure you have tried following?

    Catch ex As Exception 
               
    If Err.Number <> 0 Then DisplayAJAXMessage(Me, ex.Message.ToString.Replace("'","")) 
               
    Exit Sub 
           
    End Try 

    Monday, November 21, 2011 3:35 AM
  • User1042132515 posted

    and debug and see that after removing single quotation mark your messge should be:

    Conversion failed when converting the varchar value Select Record to data type int.

    instead of

    Conversion failed when converting the varchar value 'Select Record' to data type int.

    Monday, November 21, 2011 3:36 AM
  • User-1199946673 posted

    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 & "'")

    After solving your problem, start reading what you should do to prevent SQL injections...

    http://www.mikesdotnetting.com/Article/113/Preventing-SQL-Injection-in-ASP.NET

    Monday, November 21, 2011 3:41 AM
  • User988538322 posted

    Yes i m Sure. ok i will send you a vedio where you can see working Easily. 

    Monday, November 21, 2011 3:49 AM
  • User988538322 posted
    Patricgreat check this link for easily understanding. thanks http://www.youtube.com/watch?v=qGtw_5rQ1qQ&feature=feedu
    Monday, November 21, 2011 10:31 PM
  • User988538322 posted
    Patricgreat check this link for easily understanding. thanks

    http://www.youtube.com/watch?v=qGtw_5rQ1qQ&feature=feedu
    Monday, November 21, 2011 10:32 PM
  • User1042132515 posted

    have you checked the video uploaded? its repeating the same content? can you please cross check?

    Tuesday, November 22, 2011 8:05 AM
  • User1042132515 posted

    hey, your problem got solved?

    Sunday, November 27, 2011 12:17 AM
  • User988538322 posted

    Yes in vs 2005 its Not Possible. But in Vs 2008 or Vs 2010 its work perfectly. i don't know why. 

    Sunday, November 27, 2011 11:57 PM
  • User1042132515 posted

    ohh... means there was no issue of quotation mark?? can you please paste the code which worked?

    Monday, November 28, 2011 12:45 AM
  • User988538322 posted

    Code is same. as above mention. the problem is in AJAX Script Manager and Update Panel in VS 2005. 

    Monday, November 28, 2011 2:18 AM
  • User-891884238 posted

    I have the same problem, but in Visual Studio 2008 SP1.

    Some idea?

     

    Thanks,

    Eva Janakieff

    Thursday, September 19, 2013 4:19 AM
  • User-891884238 posted

    I resolved it!

    My problem was the content of the message I want to show with the DisplayAjax Message.

    I include the content of a string variable that contains some spaces, intros...

    I made a TRIM() of that string, and the message is showed.

    Thanks,

    Eva Janakieff

     

    Friday, September 20, 2013 8:02 AM