[Solved] JavaScript Error: ReferenceError: platform is not defined

makumbi
 
on Nov 15, 2022 09:40 PM
233 Views

Set TextBox on ASP.Net GridView row selection using JavaScript from Code Behind

I have tried it but is not generating any voice with Mozilla Firefox and i wanted it in a way that the moment i click the ok button the voice should automatically be played.

Thank you for the big effort.

It is also showing this error if i open it with other browsers like chrome.

ReferenceError: platform is not defined
Download FREE API for Word, Excel and PDF in ASP.Net: Download
PrinceG
 
on Nov 16, 2022 12:19 AM
on Nov 16, 2022 12:20 AM

Hi makumbi,

Please refer below sample.

HTML

<asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" Width="405px">
    <Columns>
        <asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
        <asp:BoundField DataField="Name" HeaderText="Name" />
        <asp:BoundField DataField="Country" HeaderText="Country" />
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button Text="View" runat="server" OnClick="OnViewDetails" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<input id="text" runat="server" />
<button onclick="talk()">
    Talk It!</button>&nbsp;
<button onclick="listen()">
    Voice</button>&nbsp;
<select id="Language">
    <option value="en">English</option>
    <option value="fr">French</option>
</select>
<script src="webspeech-master/src/webspeech.js" type="text/javascript"></script>
<script type="text/javascript">
    var speaker, listener;
    window.onload = function () {
        ws = webSpeechNoConflict();
        try {
            speaker = new ws.Speaker();
            speaker.onEnd(function () {
                console.log('just finished talking...');
            });
        }
        catch (ex) {
            console.log(ex);
            speaker = null;
            document.getElementById("status").innerHTML = ex;
        }
        try {
            listener = new ws.Listener();
        }
        catch (ex) {
            console.log(ex);
            listener = null;
            document.getElementById("status").innerHTML = ex;
        }
    };
    function talk() {
        if (speaker) {
            speaker.speak(document.getElementById("Language").value, document.getElementById("text").value);
        }
    }

    function listen() {
        if (listener) {
            listener.listen(document.getElementById("Language").value, function (text) {
                document.getElementById("text").value = text;
            });
        }
    }
</script>

Namespace

C#

using System.Data;

VB.Net

Imports System.Data

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[] { 
                            new DataColumn("CustomerId"),
                            new DataColumn("Name"),
                            new DataColumn("Country")});
        dt.Rows.Add(1, "John Hammond", "United States");
        dt.Rows.Add(2, "Mudassar Khan", "India");
        dt.Rows.Add(3, "Suzanne Mathews", "France");
        dt.Rows.Add(4, "Robert Schidner", "Russia");
        gvCustomer.DataSource = dt;
        gvCustomer.DataBind();
    }
}

protected void OnViewDetails(object sender, EventArgs e)
{
    GridViewRow row = (sender as Button).NamingContainer as GridViewRow;
    string customerId = row.Cells[0].Text;
    string name = row.Cells[1].Text;
    string country = row.Cells[2].Text;
    string message = "\\nCustomerId: " + customerId  + "\\nName: " + name  + "\\nCountry: " + country;               
    text.Value = name;
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + message + "');", true);
}

VB.Net

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As New DataTable
        dt.Columns.AddRange(New DataColumn() {
                            New DataColumn("CustomerId"),
                            New DataColumn("Name"),
                            New DataColumn("country")})
        dt.Rows.Add(1, "John Hammond", "United States")
        dt.Rows.Add(2, "Mudassar Khan", "India")
        dt.Rows.Add(3, "Suzanne Mathews", "France")
        dt.Rows.Add(4, "Robert Schidner", "Russia")
        gvCustomer.DataSource = dt
        gvCustomer.DataBind()
    End If
End Sub

Protected Sub OnViewDetails(ByVal sender As Object, ByVal e As EventArgs)
    Dim row As GridViewRow = TryCast((TryCast(sender, Button)).NamingContainer, GridViewRow)
    Dim customerId As String = row.Cells(0).Text
    Dim name As String = row.Cells(1).Text
    Dim country As String = row.Cells(2).Text
    Dim message As String = "\nCustomerId: " & customerId & "\nName: " & name & "\nCountry: " & country
    text.Value = name
    ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('" & message & "');", True)
End Sub

Screenshot