Convert HTA into ASP.net app...if last key press = .03 than send data to MS SQL DB...

GlobaLevel
GlobaLevel used Ask the Experts™
on

The goal is to have an app that would begin timing at last keypress..once it reached 3 seconds..it would send whatever data is in the textbox/label control to a DB.... then it would delete whatever is in the control...fresh for a new session...

Here is the thread that got it to the HTA...

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26531086.html#a33929706
<html>
<head>
<title>My HTML application</title>
<HTA:APPLICATION
  APPLICATIONNAME="Text Collector"
  ID="TextCollector"
  VERSION="1.0"/>
</head>

<script language="VBScript">
Option Explicit
Dim intTimer,strStatus
Sub Window_OnLoad

  'This method will be called when the application loads
  'Add your code here
intTimer = window.setTimeout("TimedOut", 3000) 'milliseconds
RestartTimer()
End Sub
  
Sub RestartTimer()
window.cleartimeout(intTimer)  
intTimer = window.setTimeout("TimedOut", 3000) 'milliseconds
strStatus="active"
spstatus.innerhtml=strStatus
End Sub


Sub KeyPressedinInput()
RestartTimer()
spdebug.innerhtml=taInput.value  
End Sub


Sub TimedOut()
	If tainput.value <> "" Then
  		StoreData(tainput.value)
  		taInput.value=""
  	End If
  	
  	strStatus="Hibernating"
  	spstatus.innerhtml=strStatus
  	
  	
End Sub

Sub StoreData(strText)
	taoutput.value=taoutput.value & strText
	
'	Const adOpenStatic = 3
'	Const adLockOptimistic = 3

'	Set objConnection = CreateObject("ADODB.Connection")
'	Set objRecordSet = CreateObject("ADODB.Recordset")

'	objConnection.Open _
'    "Provider=SQLOLEDB;Data Source=atl-sql-01;" & _
'        "Trusted_Connection=Yes;Initial Catalog=Northwind;" & _
'             "User ID=fabrikam\kenmyer;Password=34DE6t4G!;"

'	objRecordSet.Open "SELECT * FROM GeneralProperties" , _
'    objConnection, adOpenStatic, adLockOptimistic

'	objRecordSet.AddNew
'	objRecordSet("Recordedtext") = strText

'	objRecordSet.Update

'	objRecordSet.Close
'	objConnection.Close
	
	
End Sub

</script>

<body bgcolor="white">

<!--Add your controls here-->

<textarea name="taInput" id="taInput" rows="25" cols="80" onKeyPress="KeyPressedinInput"></textarea>
<br>
<br>
<textarea name="taOutput" id="taOutput" rows="5" cols="80"></textarea>
<br>
<span name="spStatus" id="spStatus" ></span>
<br>
<span name="spDebug" id="spDebug" ></span>
<!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
here is your Default.aspx page
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
   
</head>
<body>
    <form id="form1" runat="server">




<!--Add your controls here-->

<textarea name="taInput" id="taInput" rows="25" cols="80" onKeyPress="KeyPressedinInput" runat="server"></textarea>
<br>
<br>
<textarea name="taOutput" id="taOutput" rows="5" cols="80" runat="server"></textarea>
<br>
<div id="spStatus" name='spStatus" runat="server"></div>

<br>
<div id="spDebug" name='spDebug" runat="server"></div>

<!--{{InsertControlsHere}}-Do not remove this line-->

 






    </form>
</body>
</html>

Open in new window

and here is your code page Default.aspx.vb
mports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
    Public intTimer As Timer
    Public strStatus As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            

        intTimer = New Timer()

        intTimer.Interval = 3000

        RestartTimer()
    End Sub

  

    Sub RestartTimer()

        intTimer.Interval = 3000
        strStatus = "active"
        Me.spStatus.InnerHtml = strStatus
    End Sub


    Sub KeyPressedinInput()
        RestartTimer()
        Me.spDebug.InnerHtml = taInput.Value
    End Sub


    Sub TimedOut()
        If taInput.Value <> "" Then
            StoreData(taInput.Value)
            taInput.Value = ""
        End If

        strStatus = "Hibernating"
        Me.spStatus.InnerHtml = strStatus


    End Sub

    Sub StoreData(ByVal strText As String)
        taOutput.Value = taOutput.Value & strText
        Dim result As Integer
        Dim sql As String
        Dim strConn = "Provider=SQLOLEDB;Data Source=atl-sql-01;" & _
              "Trusted_Connection=Yes;Initial Catalog=Northwind;" & _
                     "User ID=fabrikam\kenmyer;Password=34DE6t4G!;"
        Dim conn As SqlConnection
        sql = "UPDATE GeneralProperties SET Recordedtext='" & strText & "'"
        Try
            conn = New SqlConnection(strConn)
            conn.Open()

            Dim cmd As SqlCommand = New SqlCommand(sql, conn)
            ' Configure the SqlCommand object
            If Not cmd Is Nothing Then

                With cmd
                    .Connection = conn
                    .CommandType = CommandType.Text      ''Set type to Text
                    .CommandText = sql                    ''Specify sql to run
                End With
            End If

            result = cmd.ExecuteNonQuery()
        Catch ex As SqlException
            Console.Write("SQL ERROR: " & ex.Message)
        Catch ex As Exception
            Console.Write("ERROR: " & ex.Message)
        Finally
            conn.Close()
        End Try



    End Sub



End Class

Open in new window

GlobaLevelProgrammer

Author

Commented:
from design I can drop a sqldatasource from toolbox that will begin the sql wizard..right..even if the control is embedded in the HTA?
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

not sure I understand what are you talking about?
GlobaLevelProgrammer

Author

Commented:
YZlat...

I tried the code...but it doesnt seems to register the keypress...wehnI run as a stand alone .html app it runs fine...but when I try it through the IIS...it doesnt function....is this an IIS security issue?
GlobaLevelProgrammer

Author

Commented:
when I run as a stand alone .html it runs fine...when I run as .html or .aspx going thru the IIS..all the client events stop working...
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | Consultant

Commented:
ASP.net tries to attach these events on the server side, instead of putting them in the markup, try using the following code in your Page_Load

 taInput.Attributes.Add("onKeyPress", "KeyPressedinInput")

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial