hi i have usercontrol on which there is one file upload control, user control is inside Tab container which on aspx page.hirarchy is like bellow:
1.Master Page
2.aspx Page having ajax tab control.
3.User control which is inside tab container.
4.file upload control which is on user control. and submit button
Problem i am facing:
When i click on submit button as page load event is called before buttons on click event value of file upload control is getting nulll.
could you please tell me how can i fetch the file upload control value after postback.
thanks is advance.
The file upload control does not retain the posted file with each request.
When the user selects a file, it will be available in the next PostBack request that occurs.
You should check for a PostedFile on each postback and save this file on the server.
Keep a reference to its path in the ViewState.
Then you can process the file when the user has finished all inputs.
Related
I have an application, in which on an aspx form I am loading a web user control at runtime based on the selected input. This user control contains a datagrid, which is populated on page_init of the ascx file.
Now the problem is upon editing I am unable to save the data, the save button which is there on the user control doesn't fire, and as a result I am trying to access the gridview on my aspx page to save the values.
I tried using the property, session everything possible but no luck.
Can anyone please explain how to achieve this? With example please.
I have a Master page with a script manager. I have a content page with an update panel. Inside the update panel i have several User controls which initially are all visible=false. After Opening one of the User control, i have not been able to attach my js file using
RegisterClientScriptInclude. I have used:
ScriptManager.RegisterClientScriptInclude(Page, this.GetType(), "key5", ResolveClientUrl("~/js/configurator.js"));
on the master page, on the content page and in the user control code behind. none of which shows that the js file is being loaded. i have always been able to do this but all controls have been visible from begining.
Could someone point how to load the script so that it is available for the User Control?
All I had to do is create a javascript handler like this so that it could be pick up after visible=true. $("button").live("click", function(e){......});
AsyncFileUpload control start uploading file as soon as user select file. But normal behavior is, first user browse file then click submit button then file uploading should start. How to achieve this functionality in case of AsyncFileUploadf control?
The whole point of the AsyncFileUpload is that it uploads the file(s) asynchronously. Allowing the user to select other files while the control continues to upload the files already selected.
If you want browse for file, then submit file functionality, then you should use the standard FileUpload control.
To achieve this you need to download the source, and modify the AsyncFileUpload tool's source code.
I'm creating a page that users can upload a file to the webserver. After upload the page will then have a link to the file that has just been uploaded, along with any other files that have already been uploaded.
As I am programatcially creating links to the files which have been uploaded, I have to do this in page_init or else the link button won't fire off it's event when clicked. MY web page does all this - it creates the link buttons and when I click on them, it calls the event method required i.e. a sub to download the file.
OK, the problem I've come accross is: when I click upload (to upload the file) - the page_init sub is called, displaying all the previously uploaded files as link buttons. Then my btnUpload_click sub is called, which uploads my current file.
The only prob is the current file hasn't been displayed? I can only display links in the page_init, but because btnUpload is called after the page_init, the current file isn't uploaded until after page_init and therefore not dislayed?
Any ideas how to get around this?
Have list of all the server side links as member of your class: List<LinkButton> myLinks = new List<LinkButton>();
When you build the links don't add them to the page yet, add them to the List instead: myLinks.Add(oNewLink);
In the btnUpload_Click method, add new link to the global list with the proper values.
Add the links to the page in the Page_PreRender function, which happens after the button click.
If you need further help implementing this logic let me know. :)
if you are getting/saving the list of previously uploaded files from Session variable or Database, then at the end of btnUpload_click event, you can simply redirect the page to itself. Like Response.Redirect("PageName.aspx");
I would like to display the size of the file that was chosen via the Browse button of the FileUpload control.
Ideally, this value is displayed immediately after the user chooses the file but BEFORE the "Upload File" Button is clicked.
I have and on a webform. The Button looks like this:
<asp:Button ID="UploadButton" runat="server" onclick="UploadButton_Click" Text="Upload File"/>
The onclick event for the button control results in a postback and the file is uploaded.
I know how to get the size of the file but not before the Upload File button is clicked and a postback occurs.
Is there an event associated with the FileUpload web control that could submit the form (i.e. postback) without the clicking of the button?
The whole intent is that I want to give the user a feel for how long the upload might take...set a different expection for a 10mb file than for a 2kb file, etc.).
The problem is that there's no way to find out the size of file on the client side without posting back. You could use Ajax, but that would mean uploading the file first anyway.
This can only be done using an ActiveX control of some kind. I would recommend using something like the Silverlight FileUploader because it gets the size of the file before posting back and even has a nice progress indicator.
UPDATE: If you want to trigger a postback or Ajax Request after the user clicks browse, the client side event is "onchange". Here's an example of how to use the onchange event.
<asp:FileUpload runat="server"
onchange="alert('you selected the file: '+ this.value)" />
You could have the onchange, trigger an ajax to upload the file first and then update a label showing the size of the file. The problem with this is that if it is a large file, it defeats the purpose of letting the user know before hand that it will take a long time.
Here's another recommendation: There's a jQuery plugin that uses flash to determine the size of the file before uploading and it's very easy to use. Check it out at jQuery Uploadify