here's the code I've come-up with so far:
protected void Page_Load(object sender, EventArgs e)
{
try {
serialPort1.PortName = "COM4";
serialPort1.BaudRate = 9600;
serialPort1.Open();
this.serialPort1.DataReceived += new
System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
Label1.Text = "Connected";
UpdatePanel1.Update();
}
catch (Exception ex) {
}
}
string x = "";
private void serialPort1_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e){
x = serialPort1.ReadExisting();
TextBox1.Text = x;
UpdatePanel1.Update();
}
the problem is after the code runs the text box remains empty... (Im using AJAX update panel to refresh the textbox text) the thing is when I set breakpoints during debug, the data received from the serial port is in the variable and is set as the new textbox text but when the code finishes nothing is displayed.... I'm pretty sure the updatepanel works because I've tested it.
PS The serialport is connected to an rfid reader and im trying to read tags. I have successfully coded a windows form app to do what I want but I need to migrate it to ASP.NET
Reading data from serial port in ASP.NET application will only work if the reader is connected to the server (not the machine that is running the browser). It seems to be working only because you are testing it locally.
The serialPort1 object will be destroyed after the initial page render is complete. The ASP.NET page only lives until the page is rendered. Then it is destroyed. The next request again recreates all objects. So the serial port would be opened again and again every time the browser goes to the server.
UpdatePanel only changes the classic browser requests into AJAX - it does not change how ASP.NET server processing works. It is still request-response actions triggered by the client browser. In your case the UpdatePanel would have to query the server on a timer.
Your best bet is to create a ActiveX control based on your Windows Forms code and embed that in your website.
Related
I am using webbrowser into Windows application.
When webbrowser navigate first time, there is no problem.
But calling second time webbrowser navigate captcha does not change.
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("uyg.sgk.gov.tr/SgkTescil4a");
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.AllowNavigation = true;
}
To prevent page caching on your client, which may be the reason why you see the Captcha not changing use
webbrowser1.Refresh(WebBrowserRefreshOption.Completely).
to clear the cache. If its not a client side caching issue, then its a problem with the website.
I would like to make and App that when users set an alarm (like wake up alarm) and alarms sounds, doesnt show a message dialog to confirm and stop the alarm.
On web I have discovered some methods called Obscured and UnObscured that fired when the message's alarm shows, but the message still showed!
In Code:
public OverAlarmPage()
{
InitializeComponent();
PhoneApplicationFrame phoneAppRootFrame = (Application.Current as App).RootFrame;
phoneAppRootFrame.Obscured += OnObscured;
phoneAppRootFrame.Unobscured += Unobscured;
}
void OnObscured(Object sender, ObscuredEventArgs e)
{
txtStatus.Text = "Obscured event occurred";
}
void Unobscured(Object sender, EventArgs e)
{
txtStatus.Text = "Unobscured event occurred";
}
I just want to make stop the alarm sound with the vibrating of mobile (with gyroscope) but without the hell message!
There are any solution or is this a O.S feature that i cant touch?
The built in notification classes (Alarm and Reminder) don't support any customization of the UI that is displayed when they are triggered.
The only alternative I can think of would require the application to remain running (possibly under the lock screen) and then you just play the sound from the app at the appropriate time.
Obviously this requires that the app remain running though.
Other than that you will be prevented from trying to create the behaviour you are after.
I searched the internet over and over, and this seems to be very straightforward, but somehow it's not working.
I'm trying to create a web forms application in C#.
Button1 is supposed to download a lot of data from a website, and I want to Label1 to display "downloading" while the code in Button1 runs, and "done" after the code finishes, but Label1 is not changing at all after button click.
code is below:
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "downloading";
//code for downloading data
Label1.Text = "done";
}
That's not going to work. That's all server-side code. The updated HTML is not sent back to the browser until after the Button1_Click handler is finished executing. So the browser will only see the "done" label text. Never the "downloading" text.
The easiest way to achieve your desired effect is to use client-side javascript (maybe using jquery) to update the label text to "downloading" before you submit the form. You can put your client-side javascript in the OnClientClick property of the asp.net button. The server-side code can then download the data and change the label text to done.
I don't know if this will still be helpful since the post is rather old, but I stumbled upon the question while searching for an answer to a question of my own.
Just use the Label1.Update() function after you change the label's text.
If you want to change text from downloading to done then you may do this:
Label lbl = (Label)this.FindControl("Label1");
if (lbl != null)
{
lbl.Text = "done";
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "downloading";
//code for downloading data
Label1.Text = "done";
Label1.Refresh;
}
Hi i want to update value in textbox when event trigger..i know how to do it in winform..but i cant do it in webform..
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
return;
else
myClass.MyEvent += new MyClass.MyEventDelegate(Default_MyEvent);
}
private void Default_MyEvent(string value)
{
txtBox.Text = value;
}
above code doesn't change text value of my textbox in asp.net but it works in winform. How to do it in webform?
*Edit
I try to create file transfer application via socket on web. I already done this in desktop application.
Basically when client open web page then client will connected to server on spesific port. and every data transmitted to client from server, then in then web form there will be an changing in text of the textbox.
Is it possible to add a serial port control to a web application. I've tried creating one programmatically, but i have issues with the port staying open. I'm not sure how to fix that except by adding a serial port control somehow to the web page. Any ideas on how I can accomplish this task? Thanks in advance.
the following is the code I currently have:
public partial class LoadCellTest : System.Web.UI.Page
{
SerialPort serialPort1 = new SerialPort("COM3",9600,Parity.None,8,StopBits.One);
protected void Page_Load(object sender, EventArgs e)
{
serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
serialPort1.ErrorReceived += new SerialErrorReceivedEventHandler(serialPort1_ErrorReceived);
}
delegate void SerialDataReceivedDelegate(object sender, SerialDataReceivedEventArgs e);
delegate void SerialErrorReceivedDelegate(object sender, SerialErrorReceivedEventArgs e);
protected void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
TextBox1.Text = (serialPort1.ReadExisting());
if (serialPort1.ReadExisting().Length == 0)
{
ListBox1.Items.Insert(0, TextBox1.Text);
TextBox1.Text = "";
}
}
protected void button1_Click(object sender, EventArgs e)
{
try
{
if (serialPort1.IsOpen)
{
serialPort1.Close();
button1.Text = "Start";
}
else
{
serialPort1.Open();
button1.Text = "Stop";
}
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
}
Turning my comments into an answer...
The serial port code is server-side code. You can't do it on the client with ASP.NET.
Creating an ActiveX or other fat client control is a load of work, and just not a good idea.
My recommendation would be to continue on with your WinForms app for the code where you need the scanner, and add a menu to it to enable you to launch a separate ASP.NET web app for the reports/data access.
If you want to make it more "seamless" for the users, you can add a form with a WebBrowser control that loads your report/data access site. To them it will just be a "part of the application".
THAT SAID, depending on the device you have connected to the port, there may be an even simpler option.
One of our barcode scanners comes with software that just takes barcode data as it's scanned and pastes it into whatever open document has focus. If you're working in Notepad, the scanned data is pasted into Notepad. If you have a web app open, and the cursor in a text box, the data simply pastes in there.
It's a simpler option to implement, BUT it's harder on the users, because if they're not technical, they're going to call you wondering why the barcode beeps but doesn't populate the text box. (The answer will be "Because your cursor isn't in the text box or the form doesn't have focus")
So I go back to recommendation #1.
Your code just accesses the serial port of the server since it is running on the server...
IF you really need to access the serial port on the client from a web app then you will need to use some technology that runs directly on the client... this could be an ActiveX control embedded into your web page...
I am really not sure perhaps a Silverlight application embedded into your web page could achieve this too...
Beware that doing so in a web page is a possible security problem !