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.
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