Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET VB.NET
Hi,
 
I want to update the label control data(text) when I open any file like Excel file.
 
Please reply.
Posted 15-Apr-13 2:14am
Comments
Prasad Khandekar at 15-Apr-13 7:21am
   
Can you explain your problem in a bit more detail?
Archana Parate at 15-Apr-13 7:46am
   
I have a imagebutton.
 
When I click on Imagebutton, it will open a file.
While opening a file, side by side a text will appear on label that on which date the file get opend. It means " File Read on 15-April-2013" text will appear on label control when file is opening.
 

the code is like below:
 
Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")
If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 "
FileOpen(fl.FullName)
end if
Archana Parate at 15-Apr-13 8:04am
   
I have a imagebutton.
 
When I click on Imagebutton, it will open a file.
While opening a file, side by side a text will appear on label that on which date the file get opend. It means " File Read on 15-April-2013" text will appear on label control when file is opening.
 

the code is like below:
 
Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")
If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 "
FileOpen(fl.FullName)
end if
ryanb31 at 15-Apr-13 7:43am
   
OK. Where are you stuck?
Archana Parate at 15-Apr-13 8:06am
   
The code is like Below :
 
Dim fl As New FileInfo("C:\inetpub\ftproot\NewFolder1\External\abc.doc")
 
If (fl.Exists()) Then
lbl_readon.Text = "File Read on 15-April-2013 " FileOpen(fl.FullName)
end if
 
Actually.
 
There is no error in the given code.
 
Actually it opens a file but it does not show the label text while opening a file.
 
Please tell me how to do it..
ryanb31 at 15-Apr-13 8:09am
   
You need to post more code. Is this part of an ajax postback? That would be why your label is not updated. If it is a full postback, it should work.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It doesn't work because you're opening the file on the UI (startup) thread. You're setting the text of the label, but since the thread is busy opening and, possibly, processing the file, the thread cannot get around to processing the WM_PAINT messages your app got to repaint the label with the new text.
 
Put the code for opening and processing the file in a background thread and it'll work. You can use explicit Threads, a BackgroundWorker component, Tasks from the Task Parallel library, or what have you.
 
Oh! And don't think you can just move the code for setting the label text to the background thread. It won't work, reliably anyway. You cannot touch UI controls from anything other than the UI thread.
  Permalink  
v2
Comments
Archana Parate at 16-Apr-13 2:14am
   
can you please show it??
Dave Kreskowiak at 16-Apr-13 8:33am
   
Nope, cause I don't have the time and it's already been shown thousands of times all over the web.
 
Read these:
 
https://www.google.com/#hl=en&gs_rn=9&gs_ri=psy-ab&tok=y8Z-s1JgksV5tJyWuRHl8Q&cp=23&gs_id=2i&xhr=t&q=how+to+use+backgroundworker&es_nrs=true&pf=p&output=search&sclient=psy-ab&oq=how+to+use+background+w&gs_l=&pbx=1&bav=on.2,or.r_qf.&bvm=bv.45175338,d.aWc&fp=8b6e51a45d6e43c7&biw=1920&bih=1105

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 15 Apr 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