Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 30-Jul-10 12:06pm
v3

Creating a string with your js in it is worthless unless you write it out to the client. Is your script being written in to the final page ? Are there any js errors on the page ? Why pop up an alert when you'e done a postback, why not just have an error field in the page ?
 
Share this answer
 
thank you for your answer
I have an error field in the page:
if textbox1.text='dataitem' then
msgbox("Right")
else
msgbox("wrong")
end if
when the word is in the database msgbox "right" is displayed

but when the word is not in the database msgbox "wrong" is not displayed
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900