Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
 
I have done some changes to my coding and tested it. It is still not working perfectly hence i hope to have some guidance here.
 
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO.Ports
 
Partial Class Main
    Inherits System.Web.UI.Page
 
    Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
 
        Dim Serialport7 As New IO.Ports.SerialPort
 
        With Serialport7
            .PortName = "COM7"
            .BaudRate = 9600
            .Parity = Parity.None
            .DataBits = 8
            .StopBits = StopBits.One
        End With
 
        Try
            Serialport7.Open()
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
 

        Dim ReceivedData As String
 
        ReceivedData = Serialport7.ReadLine()
 
        If ReceivedData.Substring(0, 1) = "T" Then
 
            TextBox1.Text = ReceivedData.Remove(0, 1)
 
        ElseIf ReceivedData.Substring(0, 1) = "H" Then
 
            TextBox2.Text = ReceivedData.Remove(0, 1)
 
        End If
 
        TextBox3.Text = System.DateTime.Now
 
        Serialport7.Close()
 
    End Sub
 
End Class
 

The errors i have encountered:
- TextBox2 is not displaying the reading, only TextBox1 is showing the reading.
- The Web form is not refreshing hence my readings are not updated. Is there any way i can auto update the Web form ?

Appreciates all guidance.
Thanks.
Posted 30-Mar-13 5:53am
Comments
Manfred R. Bihy at 30-Mar-13 17:43pm
   
As Dave already noted you need to show us the ASP.net markup as well, because this is where your caching and refresh issues arise from.
 
Regards,
 
Manfred
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First, you've got no code in here that tells the borwser to not cache the page and to refresh it every so often.
 
Second, your code will only fill one textbox, out of TextBox1 and TextBox2, and not the other, depending on the one character position you look at in the string. Just follow the if statements and the character that you're tracking in the string received and you'll understand why.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I googled a bit and found the Meta refresh to be suited to what i need.
 
i changed the if statements such that im using 2 string variables to readline and have them display at both textboxes.
 
Both the above methods may not be nicely suited but i think it will suffice for my demo project.
 
Thanks.
 
PS: I have actually tested the coding in WinForm before implementing in Web Form and they are actually displaying what i want in both textboxes while using only 1 string variable to readline. So im quite confused why it would not work the same in WebForm.
Perhaps someone can explain this ?
  Permalink  
v2
Comments
Dave Kreskowiak at 31-Mar-13 21:23pm
   
You can't really port code from Windows Forms to ASP.NET without knowing WHY the code works in Windows Forms.
 
Windows Forms maintains state, constantly. If you set the value of a textbox, that value will stay there forever, until it's changed or removed.
 
In ASP.NET, there is no state. Every time the page refreshes itself, it's rebuilt from the ground up knowing nothing about the previous contents of controls. So, if you set the value of a textbox in one refresh of the page but don't set it again in the next refresh of the page, the value disappears. Well, that is, unless you enable ViewState.
 
I suggest going through a beginners book on ASP.NET.

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,127
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 31 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100