0 Replies - 577 Views - Last Post: 07 April 2009 - 10:25 PM

#1 mineeric123  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 36
  • Joined: 12-November 08

PostBack form loads crazy

Posted 07 April 2009 - 10:25 PM

I am using a timer to create a random number perform some math, and then write a file to the server every second. Once the number is created the program updates the text boxes on the web form. Right now my program does this, but it also re-loads the entire form each time. I would like to just update the text boxes not re-load the form. Could I use a post back method? I looked for a sinpet but I could not find anything. Please help.

Thanks

Eric

VB code

Partial Class _Default
	Inherits System.Web.UI.Page
	
	Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		'create variables 
		Dim randomGenerator As New Random
		Dim amps As Integer = randomGenerator.Next(25, 30)
		Dim volts As Integer = randomGenerator.Next(110, 120)
		Dim watts As Double
		Dim KW As Double
		Dim path As String = "C:\Google\"
		watts = amps * volts

		KW = watts / 1000


		If My.Computer.FileSystem.FileExists(path & "file.txt") Then
			Dim contents As String = My.Computer.FileSystem.ReadAllText(path & "file.txt")
			Dim value As Double
			Dim file As String = "C:\Google\file.txt"

			'convert 
			value = Convert.ToDouble(contents)
			Dim saveKW As Double = KW + value
			My.Computer.FileSystem.WriteAllText(file, saveKW.ToString, False)
			txtLKW.Text = saveKW

		Else

			Dim file As String = "C:\Google\file.txt"
			Dim saveKW As Double = KW
			My.Computer.FileSystem.WriteAllText(file, saveKW.ToString, False)
			txtLKW.Text = saveKW

		End If
		txtAmps.Text = amps.ToString
		txtVolts.Text = volts.ToString
		txtWatts.Text = watts.ToString
		txKw.Text = KW.ToString

	End Sub

	Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
		Timer1.Enabled = True
	End Sub

	Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
		Timer1.Enabled = False
	End Sub

   
End Class



ASP/HTML


<%@ 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></title>
	<style type="text/css">
		#btn1
		{
			width: 72px;
		}
	</style>
</head>
<body bgcolor="#666699">
	<form id="form1" runat="server">
	<div style="height: 247px">
	
		
		<asp:Label ID="Label1" runat="server" Font-Bold="True" Text="Volts "></asp:Label>

		<asp:TextBox ID="txtVolts" runat="server"></asp:TextBox>

		<asp:Label ID="Label2" runat="server" Font-Bold="True" Text="Logging KW"></asp:Label>

		<asp:TextBox ID="txtLKW" runat="server"></asp:TextBox>
		<br />
		<br />

		<asp:Label ID="Label3" runat="server" Font-Bold="True" Text="Amps"></asp:Label>

		<asp:TextBox ID="txtAmps" runat="server"></asp:TextBox>

		<asp:Label ID="lable1" runat="server" Font-Bold="True" Text="Sim KWh"></asp:Label>

		<asp:TextBox ID="txtKWh" runat="server"></asp:TextBox>

		<br />
		<br />

		<asp:Label ID="Label4" runat="server" Font-Bold="True" Text="Watts"></asp:Label>

		<asp:TextBox ID="txtWatts" runat="server"></asp:TextBox>
		<br />

		<br />

		<asp:Label ID="Label5" runat="server" Font-Bold="True" Text="KW"></asp:Label>

		<asp:TextBox ID="txKw" runat="server"></asp:TextBox>
		<br />
		<br />

		<asp:Button ID="btnStart" runat="server" BackColor="#00CC00" 
			BorderStyle="Inset" Font-Bold="True" ForeColor="Black" Text="Start" 
			Width="80px" />

		<asp:Button ID="btnStop" runat="server" BackColor="Red" BorderStyle="Inset" 
			Font-Bold="True" ForeColor="Black" Text="Stop" Width="80px" />
		<br />
		<asp:ScriptManager ID="ScriptManager1" runat="server">
		</asp:ScriptManager>
		<asp:Timer ID="Timer1" runat="server" Interval="1000">
		</asp:Timer>
		<br />
		<br />
		
	
	</div>
	</form>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1