I want to create jQuery behind the code in VB.NET and I want that code be execute each time when I change a value in my TextBox. For now I created method which is creating my function and that code look like this:
Sub jQueryInsert()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
Dim sScript As String = ""
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT NAZIV, NAZIV_POLJA FROM [IZV_1] WHERE DATUM_ZATVARANJA IS NULL AND OPIS LIKE UPPER('%NOV%') ORDER BY KOEFICIJENT DESC;"
cmd.Connection = con
Using sda As New SqlDataAdapter()
cmd.Connection = con
sda.SelectCommand = cmd
Using ds As New DataSet
Try
con.Open()
sda.Fill(ds)
sScript = sScript & "$(function () {"
sScript = sScript & "$(document).on(""keyup"", ""input[type=text]"", function () {"
For Each Row As DataRow In ds.Tables(0).Rows
sScript = sScript & "var txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA;"
sScript = sScript & "if (document.getElementById('<%=FV.FindControl(""txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA"").ClientID%>').value == """") {"
sScript = sScript & "txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA = 0;"
sScript = sScript & "}"
sScript = sScript & "else {"
sScript = sScript & "txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA = document.getElementById('<%=FV.FindControl(""txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA"").ClientID%>').value;"
sScript = sScript & "txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA = txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA.replace(/\,/g, '');"
sScript = sScript & "var sumNOV" + Row(columnName:="NAZIV_POLJA") + " = " + Row(columnName:="NAZIV_POLJA") + " * txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA;"
sScript = sScript & "if (sumNOV" + Row(columnName:="NAZIV_POLJA") + " === 0 || sumNOV" + Row(columnName:="NAZIV_POLJA") + " === Infinity || isNaN(sumNOV" + Row(columnName:="NAZIV_POLJA") + ")) {"
sScript = sScript & "sumNOV" + Row(columnName:="NAZIV_POLJA") + " = $('#' + '<%:FV.FindControl(""txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA_sum"").ClientID%>').val("""");"
sScript = sScript & "}"
sScript = sScript & "else {"
sScript = sScript & "sumNOV" + Row(columnName:="NAZIV_POLJA") + " = $('#' + '<%:FV.FindControl(""txtNOV_" + Row(columnName:="NAZIV_POLJA") + "_KOMADA_sum"").ClientID%>').val(sumNOV" + Row(columnName:="NAZIV_POLJA") + ");"
sScript = sScript & "}"
sScript = sScript & "}"
Next
sScript = sScript & "});})"
Page.ClientScript.RegisterClientScriptBlock _
(Me.GetType, "Registered Script", sScript, True)
Catch ex As Exception
Response.Write("Error:" & ex.ToString)
Finally
cmd.Parameters.Clear()
con.Close()
End Try
End Using
End Using
End Sub
I am calling this method here:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If FormView.Visible = True Then
jQueryInsert()
End If
End If
If FormView.Visible = True Then
jQueryInsert()
End If
End Sub
But now I am getting this error:
0x800a138f - JavaScript runtime error: The value of the property '$' is null or undefined, not a Function object
This is how looks like a generated script:
<script type="text/javascript">
//<![CDATA[
$(function () {$(document).on("keyup", "input[type=text]", function () {var txtNOV_1000_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_1000_KOMADA').ClientID%>').value == '') {txtNOV_1000_KOMADA = 0;}else {txtNOV_1000_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_1000_KOMADA').ClientID%>').value;txtNOV_1000_KOMADA = txtNOV_1000_KOMADA.replace(/\,/g, '');var sumNOV1000 = 1000 * txtNOV_1000_KOMADA;if (sumNOV1000 === 0 || sumNOV1000 === Infinity || isNaN(sumNOV1000)) {sumNOV1000 = $('#' + '<%:FV.FindControl('txtNOV_1000_KOMADA_sum').ClientID%>').val('');}else {sumNOV1000 = $('#' + '<%:FV.FindControl('txtNOV_1000_KOMADA_sum').ClientID%>').val(sumNOV1000);}}var txtNOV_500_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_500_KOMADA').ClientID%>').value == '') {txtNOV_500_KOMADA = 0;}else {txtNOV_500_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_500_KOMADA').ClientID%>').value;txtNOV_500_KOMADA = txtNOV_500_KOMADA.replace(/\,/g, '');var sumNOV500 = 500 * txtNOV_500_KOMADA;if (sumNOV500 === 0 || sumNOV500 === Infinity || isNaN(sumNOV500)) {sumNOV500 = $('#' + '<%:FV.FindControl('txtNOV_500_KOMADA_sum').ClientID%>').val('');}else {sumNOV500 = $('#' + '<%:FV.FindControl('txtNOV_500_KOMADA_sum').ClientID%>').val(sumNOV500);}}var txtNOV_200_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_200_KOMADA').ClientID%>').value == '') {txtNOV_200_KOMADA = 0;}else {txtNOV_200_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_200_KOMADA').ClientID%>').value;txtNOV_200_KOMADA = txtNOV_200_KOMADA.replace(/\,/g, '');var sumNOV200 = 200 * txtNOV_200_KOMADA;if (sumNOV200 === 0 || sumNOV200 === Infinity || isNaN(sumNOV200)) {sumNOV200 = $('#' + '<%:FV.FindControl('txtNOV_200_KOMADA_sum').ClientID%>').val('');}else {sumNOV200 = $('#' + '<%:FV.FindControl('txtNOV_200_KOMADA_sum').ClientID%>').val(sumNOV200);}}var txtNOV_100_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_100_KOMADA').ClientID%>').value == '') {txtNOV_100_KOMADA = 0;}else {txtNOV_100_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_100_KOMADA').ClientID%>').value;txtNOV_100_KOMADA = txtNOV_100_KOMADA.replace(/\,/g, '');var sumNOV100 = 100 * txtNOV_100_KOMADA;if (sumNOV100 === 0 || sumNOV100 === Infinity || isNaN(sumNOV100)) {sumNOV100 = $('#' + '<%:FV.FindControl('txtNOV_100_KOMADA_sum').ClientID%>').val('');}else {sumNOV100 = $('#' + '<%:FV.FindControl('txtNOV_100_KOMADA_sum').ClientID%>').val(sumNOV100);}}var txtNOV_50_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_50_KOMADA').ClientID%>').value == '') {txtNOV_50_KOMADA = 0;}else {txtNOV_50_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_50_KOMADA').ClientID%>').value;txtNOV_50_KOMADA = txtNOV_50_KOMADA.replace(/\,/g, '');var sumNOV50 = 50 * txtNOV_50_KOMADA;if (sumNOV50 === 0 || sumNOV50 === Infinity || isNaN(sumNOV50)) {sumNOV50 = $('#' + '<%:FV.FindControl('txtNOV_50_KOMADA_sum').ClientID%>').val('');}else {sumNOV50 = $('#' + '<%:FV.FindControl('txtNOV_50_KOMADA_sum').ClientID%>').val(sumNOV50);}}var txtNOV_20_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_20_KOMADA').ClientID%>').value == '') {txtNOV_20_KOMADA = 0;}else {txtNOV_20_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_20_KOMADA').ClientID%>').value;txtNOV_20_KOMADA = txtNOV_20_KOMADA.replace(/\,/g, '');var sumNOV20 = 20 * txtNOV_20_KOMADA;if (sumNOV20 === 0 || sumNOV20 === Infinity || isNaN(sumNOV20)) {sumNOV20 = $('#' + '<%:FV.FindControl('txtNOV_20_KOMADA_sum').ClientID%>').val('');}else {sumNOV20 = $('#' + '<%:FV.FindControl('txtNOV_20_KOMADA_sum').ClientID%>').val(sumNOV20);}}var txtNOV_10_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_10_KOMADA').ClientID%>').value == '') {txtNOV_10_KOMADA = 0;}else {txtNOV_10_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_10_KOMADA').ClientID%>').value;txtNOV_10_KOMADA = txtNOV_10_KOMADA.replace(/\,/g, '');var sumNOV10 = 10 * txtNOV_10_KOMADA;if (sumNOV10 === 0 || sumNOV10 === Infinity || isNaN(sumNOV10)) {sumNOV10 = $('#' + '<%:FV.FindControl('txtNOV_10_KOMADA_sum').ClientID%>').val('');}else {sumNOV10 = $('#' + '<%:FV.FindControl('txtNOV_10_KOMADA_sum').ClientID%>').val(sumNOV10);}}var txtNOV_5_KOMADA;if (document.getElementById('<%=FV.FindControl('txtNOV_5_KOMADA').ClientID%>').value == '') {txtNOV_5_KOMADA = 0;}else {txtNOV_5_KOMADA = document.getElementById('<%=FV.FindControl('txtNOV_5_KOMADA').ClientID%>').value;txtNOV_5_KOMADA = txtNOV_5_KOMADA.replace(/\,/g, '');var sumNOV5 = 5 * txtNOV_5_KOMADA;if (sumNOV5 === 0 || sumNOV5 === Infinity || isNaN(sumNOV5)) {sumNOV5 = $('#' + '<%:FV.FindControl('txtNOV_5_KOMADA_sum').ClientID%>').val('');}else {sumNOV5 = $('#' + '<%:FV.FindControl('txtNOV_5_KOMADA_sum').ClientID%>').val(sumNOV5);}}});})//]]>
</script>
User contributions licensed under CC BY-SA 3.0