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.
Related
I have a Windows Form application in c#.
in my application i have a WebBrowser Control. in my program web browser will upload a file i want to show in my program what percentage of file is uploaded. how can i do this ?
look at web browser ProgressChanged. This event has an argument as WebBrowserProgressChangedEventArgs which holds CurrentProgress property which you can use to show with the progress bar.
WebBrowser1.ProgressChanged += WebBrowser1_ProgressChanged;
private void WebBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
ProgressBar1.Value = e.CurrentProgress;
}
Currently I am building a windows form app using c#. I have a web browser control on my form that displays a google ad. When clicked the webpage is displayed within the little 300x300 web browser control on the form. Is there a way for me to launch the default browser when the ad is clicked instead?
Thanks.
Edit: I figured out I can do so open the default browser by using Process.Start("url here"); but the browser windows is opening upon app load.
Edit Adding Code:
Form.cs
private void AdPanelNavigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
if (e.Url != null ) Process.Start(e.Url.ToString());
}
Form.Designer.cs
this.AdPanel.Navigating += new WebBrowserNavigatingEventHandler(AdPanelNavigating);
You can add Navigating event handler:
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(WebBrowser_Navigating);
void WebBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
e.Cancel = true;
Process.Start(e.Url);
}
It will open default browser instead of opening this url inside webbrowser.
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.
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;
}
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 !