0

Here's my code:

delegate void del(string data);
    public partial class CreateUser : System.Web.UI.Page
    {
        static string rfidkey;
        SerialPort serialPort1;
        //Timer timer1;
        del MyDlg;
        private delegate void SetTextDeleg(string text);
public CreateUser()
        {
            serialPort1 = new SerialPort();
            serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
            //
            timer1 = new Timer();
            timer1.Interval = 100;
            timer1.Enabled = false;
            timer1.Tick += new EventHandler<EventArgs>(timer1_Tick);
            //
            MyDlg = new del(Display);
        }
void Display(string s)
        {
            txtRFIDKey.Text = s;
}
void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Data.s = serialPort1.ReadExisting();
            //txtRFIDKey.Text = Data.s;
            MyDlg.BeginInvoke(Data.s, null, null);
        }
}
Prakash Vishwakarma
  • 814
  • 2
  • 9
  • 25
  • What error you are getting? – Murali Murugesan Mar 25 '14 at 16:12
  • A server-side timer in a webpage? The page probably has finished rendering and the page-object is destroyed before the first Tick arrives! Also: where are you expecting that serial port? You are now trying to read it on the server (and failing for the same reason as the timer) – Hans Kesting Mar 25 '14 at 16:14
  • am not getting any error, its just that the value does not get set to textbox – Prakash Vishwakarma Mar 25 '14 at 16:20
  • You need to provide more detail about what your issue is, what error you're seeing, and where in your code you're not seeing the expected result. Just putting up a code snippet with a title isn't a well formed question. – David Hoerster Mar 25 '14 at 16:21
  • I just want to set the value to textbox whenever a value is received. – Prakash Vishwakarma Mar 25 '14 at 16:27
  • Actually i am using delegate function to set value to textbox thats why it not setting value to textbox, can somebody please tell me solution for this. – Prakash Vishwakarma Mar 25 '14 at 17:33

1 Answers1

1

This cannot be done the way you are coding it. Basically, you are trying to treat your web page like a Windows application. You need to understand the the "code behind", the code you have written above, runs on one computer, and the web page, where the text field is, is displayed on another. And once the page construction code finishes running, the server can't change the page. You can use postbacks and Ajax from the web page to call back to the server, but even that might not help you with the code you trying to write.

To get a better understanding of the fundamentals of asp.net web page processing, start here: ASP.NET page life cycle explanation

Or, you can just code your page as an Application using Windows Forms, or WPF.

Community
  • 1
  • 1
user1689571
  • 495
  • 1
  • 4
  • 17