I created an ASP .NET Web Forms application from Visual Studio 2017 creator with C# as a language. I did minimum changes to the template and my web page loads a 3D image, takes a few additional parameters via Buttons and Text fields, sends it for processing to server. There it lands in a directory where it is processed by a commercial program, independent of Visual Studio, which initially writes to a directory with an image ID (say ABCD) and into a directory with an image taking date (say 20170629), after some processing, 2-5 minutes, it writes the results of the analysis into a new folder with a current date (say 20171031) into a text file where the name consists of 15 digits code and a known extension (say 123456789012345.txt). It is within Java Derby database, for which I did not find any connectors from .NET.
The web page meanwhile shows the summary of data sent. What I got working is the Button which while pressed checks if the mentioned directory (20171031) is already created shows the asp:UpdatePanel with progress (1/3 stages passed, 2/3 stages passed etc.) and when the file 123456789012345.txt is ready it gets the data from it and on the server side it calculates some values and displays them. Because of waiting there are several public async Task and public async Task methods to search for file appearance.
I wanted to avoid manual pressing of the Button, so that the processing stage is shown and once the file 123456789012345.txt is ready the values is calculated. For the moment I tried various ways, but without success. I prefer to avoid reloading the whole page every 30 seconds, because the user may get confused.
asp:UpdatePanel, as far as I understand needs pressing of the Button or some other interaction from the user side. If I use in aspx.cs file in Load_Page method the UpdatePanelName.Update(); for whatever reason the panel is not updated. Due to the use of await CalculateImageAsync(), the only way I found to have it in Page__Load is to have it as protected async void Page_Load(object sender, EventArg e) , but when page is loaded, it never loads. Anything else needs user interaction, which I want to avoid. I got stuck...
I am new in ASP .NET and C#, so maybe I do something wrong or miss some nice .NET method. I would be obliged for help. I have seen pages doing the job like I want, for example in the journals, where you submit a DOCX file where it is converted to PDF - once you submit it after some time you get a page with resulting PDF.
Regards, Marcin
Related
I have a project in C# that needs to upload files in a page with a lot of others information.
Problems:
1 - File upload doesn't give any feedback for the user, so they can't know how long will takes (doesn't work with UploadProgress and UpdatePanel).
2 - Some validations I can't do with javascript (relationships for example), so if I get any error on the server side, FileUpload loses the file and the user needs to upload the whole file AGAIN.
3 - End user have a really poor link, so for 10mb will takes a long time (10mb is the maximum allowed).
Solutions (none of them works great):
1 - I can use a client side file upload with javascript (like uploadify) and get the percentage, but works as async method so I need to block the screen to don't allow the user to do another things. My worry is more about when I receive the file and save it, because I need to link this file with the other entity if not I will lose the bridge between the file and the entity. (Same happens with the AsyncFileUpload Control). This doesn't solve the problem number 2.
2 - Just do everything synchronous as FileUpload, when all the files arrive to the server, save the file and put all the informations that I need in HiddenFields, so if I get any error on the server side I can recover the file. The problem is that I can't give any feedback for the user while he uploads the file. This doesn't solve the problem number 1.
3 - Split all the files from the others entities (this will mess a lot the project) and upload file individually. The problem is that if I do that I need some mechanism to create the link between the file and the entity AND I can't allow to use the file more than once, so probably this will request a lot of resources to check it. This solves the problems listed but I think create another, complex for the user and a lot of new verifications for the system.
4 - Create 2 buttons, one button VALIDATE for validations on the server side (with no file uploads) and after this check, allow the user to click on the SAVE button. This doesn't solve the problem number 1.
Well, as you can see I'm thinking a lot about the problem but I can't find a really good solution. One that fits all my needs. Anyone have a idea?
PS: I have FileUploads inside repeaters as well, so the IDs are automatics.
I want to create a program which will automatically fill in certain blank spaces in multiple HTML pages.
For instance I have to go through this kind of flow
Log in page where I used GetElementById("").InnerText to fill in the blanks and GetElementById("").InvokeMember("click") to progress to the next page.
Second page requires me to navigate to a different page hence I used webBrowser1.Nagivate("").
The whole program mainly revolves around these two processes, navigation and auto filling. Currently, I am stuck when the webform navigates to the next webpage but is unable to read ID for fields.
Is there any way to go about it? Or any links which might be helpful?
I have a ASP.NET app that at one point generates a PDF file and loads the next page. I can easily do this with two separate buttons but it is made much tougher when I try to do this with one button.
When both are fired by the same button the PDF will download but the page will not load. I even had the thread sleep after the file was transmitted but it would wait but then stop afterwards.
I have attached the code that I have been trying to make work:
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=labels.pdf");
Response.TransmitFile(Server.MapPath("~/"+randomNumber.ToString()+".pdf"));
Server.Transfer("~/createshipment.aspx", true);
You can't have two different responses from the server but you're trying to do so.
First - you'd like the server to return a PDF.
Second - you'd like the server to return the createshipment.aspx page.
This is just against the communication protocol. Probably the best solution is already presented by another user, competent_tech - you could open a new window (javascript's window.open) and this new window would return the PDF and in the same time the main window could post to the server and be redirected to the createshipment.aspx.
So in a nutshell you want to navigate to the next page that says something like "thank you for downloading this file" and start the download.
What you should do is on your button click you need to generate PDF and save it somewhere (on disk or DB - whichever is easier in your app), store the name/location of the new file (or primary key from DB) in a session variable and redirect to the next page. No reason to do transfer here. Then on that next page you should add a hidden iframe that points to your saved file.
Alternatively your button click could be just a link to the next page, which includes a hidden iframe pointing to the page that generates PDF. This is a bit simple but wouldn't work so well if you need to pass parameters from original page to the page that generates PDF.
This is because server.transfer "...terminates execution of the current page and starts execution of a new page by using the specified URL path of the page".
Your best bet is to open a new window in the client that gets the PDF and then perform whatever postback is needed to move the user to the next page.
I know this is old, but I'm just seeing it (looking for similar info myself).
I'm going to guess that this is causing issues:
Response.TransmitFile(Server.MapPath("~/"+randomNumber.ToString()+".pdf"));
You would need to map the path to the actual file and not some randomly created filename - or am I missing some steps?
I'm facing the following issue:
I have a C# asp.net file upload form with a submit button. After the form is submitted the file is uploaded and post-processing is started. The point is that the post-processing can take up to several minutes.
I would like to create some kind of asynchronous call of the post-processing function with showing information to the user.
So, the steps should be:
file form is submitted by user and upload is started
after the file is uploaded some information is shown to the user (e.g. "Processing..." or some loading-bar animation, etc.)
Meanwhile, the post-processing function is automatically started running in a background
After the post-processing function is finished the user is automatically redirected to another page
When i was searching the Internet I've found several examples but mostly only about asynchrounous call of functions, asynchrounous file upload (PageAsync method, etc.).
Any idea or techniques I should use or some tutorial?
Thanks in advance
That all depends on how fancy you want to get;
Meta-refresh that reloads the page until the background operation is finished
Some kind of ajax call that checks some resource for when the processing is done
HTML5 websockets. if supported, which it probably isn't.
Personally I would use the number 2. and use jQuery to poll the upload page every 500ms or something.
You can use AJAX
http://geekswithblogs.net/ranganh/archive/2008/04/01/file-upload-in-updatepanel-asp.net-ajax.aspx
http://vinayakshrestha.wordpress.com/2007/03/13/uploading-files-using-aspnet-ajax-extensions/
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=upload+using+Ajax&qscrl=1#sclient=psy&hl=en&qscrl=1&source=hp&q=upload+using+Ajax+in+asp.net&aq=f&aqi=&aql=&oq=&pbx=1&fp=db9c4fafd449a821
The jquery/flash control uploadify will allow you to do this easily. They also provide a method for asynchronously calling a method on the event that the file upload completes as described in this comprehensive documentation.
I have looked at a lot of places for a good example, and this is the one I like the best so far.
It does not handle the uploading, but it does a fine job at showing real progress to the user and it is not difficult to implement
http://inov8.wordpress.com/2010/08/29/c-asp-net-creating-an-asynchronous-threaded-worker-process-manager-and-updatepanel-progress-monitor-control/
A lot of lead up:
I have a simple ASP .NET 3.5 data entry webform with a series of dropdown lists, text boxes, and text areas and user authentication is being handled by Active Directory.
The user enters a alphanumeric id, and clicks a button. The button's onclick() in the aspx.cs:
1. calls a stored procedure to determine if it a new record, or the existing data if it already exists
2. if the record exists, then pre-fills the form with the existing values.
There are three textboxes which have been extended to use ASP .NET AJAX AutoComplete (each contained in their own asp:UpdatePanel), which also postback successfully.
When the user is done entering the data, there is a single button to save the record, which:
1. calls a stored procedure, which either inserts or updates accordingly
2. clears the webform
3. displays a quick success message.
There have been over 4000 records inserted and updated through this form since it's launch. I now have a problem where there is ONE record that cannot be updated, it was inserted a month ago, through the same form, without issue.
In Internet Explorer (6, 7 and 8): When you click the save button, it asks for you to provide your domain username and password. Entering a valid username and password displays the "Internet Explorer cannot display the webpage" screen.
In Firefox 3: When you click the save button, it displays the "Connection interrupted" screen. Clicking the "Try Again" button does not change the results.
There are no entries in the logging that the application uses, the server's Event Log, nor for SQL Server 2005.
I have tried:
- on different computers, and it failed.
- with different users, and it failed.
- with numerous other records, and they update perfectly.
I have loaded the record into the test environment in two different manners:
1. copied and pasted directly from the production database to the test database
2. copied and pasted directly from the production webform to the test webform.
The issue does not happen in test or my local development system. Both production and test are running ASP .NET 3.5 SP1.
I even saved a copy of the production page which is failing and the test page which works as HTML and ran them through Total Commander's "Compare Files by Content" function, in the hopes that the differences would be highlighted in red to be nice and obvious. The only differences were in the areas auto-generated by .NET at runtime, and the occasional place where a dropdown's item list has more entries in production then in test.
I realize there is probably something wrong with the data that is causing the final postback to fail, but it appears to be failing before the postback even starts. I have looked through the record's data through viewing the source of the loaded aspx page and in the database in the hopes of finding a stray invisible character or a textarea that has too many characters that may be causing it to choke, but no luck.
A coworker suggested setting viewStateEncryptionMode="never" in the web.config and this has 'fixed' the problem, and the record can now be updated without error.
Unfortunately, I cannot provide the data that is causing the form to fail.
My question:
Does anyone have an idea why this happened in the first place or why setting viewStateEncryptionMode="never" fixed it? A better solution than setting the ViewStateEncryptMode to never would also be welcome.
Thanks!
First, and most important - besides .Net 3.5 SP1 - make sure you have the latest patches installed on the server (this should always be the first step).
Assuming the server is up to date, I'd start by checking the firewall and anti-virus software on your server (they should have logs). Anti-virus can block web sites that use suspicious code - like a known JavaScript exploit (I'll admit I tried that one. For science). It's possible a specific combination on the viewstate looks like suspicious code or file (seems weird, but possible).
Next you can check the IIS. Enable logging and see if you get any errors. Check if you have any isapi filters installed (these can be in several places - the 'Web Service Extensions' folder, or a tab on the web site's Properties, or one of its parents' Properties)