Javascript messagebox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bassemG
    New Member
    • Oct 2009
    • 7

    #1

    Javascript messagebox

    This program in asp.net 2.0 is a Spanish/English Dictionary.
    It consists of two textboxes,one button and a datalist. The datalist is bound to an acces database consisting of two columns; One Spanish and one English. When a user enters a Spanish word in textbox1 and clicks the button, the meaning of the word appears in textbox2. Now sometimes a user enters a word that is not in the database. I want, in this case, to have a javascript messagebox to popup saying “Either the word is not listed or misspelled”.
    I tried several javascripts to popup in code behind but that did not work. I know that a clientside should be included but I am not able to do that.
    The sub below is the one I am using to fetch the words and it is working perfect as long as I enter a word that is already in access database. The words in the rows in database are separated by hyphens so I am using a “Split” fuction which is also working perfectly.

    *************** *************** *************** ********
    Code:
    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
            If e.Item.ItemType = ListItemType.Item Or _
         e.Item.ItemType = ListItemType.AlternatingItem Then
                Dim ds As SqlDataSource
                ds = CType(e.Item.FindControl("Spanish"), _
                SqlDataSource)
                Dim Words() As String
                Dim arySpanish() As String
                Dim strSpanish As String
                Dim i As Integer
                Dim strScript As String = DataBinder.Eval(e.Item.DataItem, _
                    "English").ToString()
    
    ‘The below 7 lines is where I am trying to get the js messagebox but it is not working
                TextBox1.Text = strScript
                If TextBox1.Text <> strScript Then
                    ClientScript.RegisterClientScriptBlock(Me.GetType(), "ClientScript", "alert ('wrong')", True)
                    Dim streng As String = "<script language='JavaScript'> alert('wrong') </script>"
                End If
    
                strSpanish = DataBinder.Eval(e.Item.DataItem, _
        "spanish").ToString()
                Words = strSpanish.Split("-")
                arySpanish = strSpanish.Split("-")
                strSpanish = ""
                For i = 0 To UBound(arySpanish)
                    strSpanish = strSpanish & arySpanish(i) & Environment.NewLine
                    TextBox2.Text = strSpanish
                Next
                End If
        End Sub
    *************** *************** *******
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    posted in the Classic ASP forum on accident. I will move it to the ASP.NET forum.

    Jared

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      I think that I would probably include the JavaScript into the page (in the <head> section of the page) so that you can call it on the JavaScript's window onload event. Have the JavaScript function check a HiddenField on the page to determine whether or not the message should be displayed....se t the HiddenField in your C# or VB.NET server-side code.

      -Frinny

      Comment

      Working...