ASP.Net file upload with an empty posted files collection - asp.net

I have an ASP.NET file upload control which sits as part of a form. The file upload control is on the content page while the form definition is on a master page across the site. I've added multipart/form-enc to the form on the master page.
I'm using jQuery to submit the form as I show a dialog box from jQuery UI.
When I post, no file is returned to the server. The file upload control has no file and HttpFileCollection is empty. How can I find the posted file?

Most dialogs take your content, wrap it, and place the result just before </body> in the page...this is a problem in ASP.Net because that's outside the <form></form>, it needs to be inside to be included in the POSTed data.
When you create the dialog, make it append inside the <form> when it finishes instead of the <body>, for example this is what you'd do with the jQuery UI dialog:
$("#myDiv").dialog({ ...options... }).parent().appendTo("form:first");
Now that it's been moved inside the <form>, it should post correctly.

Related

Asp.net fileUploader(brettle.web) is not working on post back

I am using a third party file uploader which is same as asp.net file uploader control.
On a page before post back(clicking a button in gridview) the file name gets empty from file uploader and on code behind can't get file.
There were update panels on page. I have also removed them but no affect.
I've checked the Brettle.Web FAQ http://neatupload.codeplex.com/documentation and found the following answer to a very similar problem:
Q: Why are filenames cleared on postback?
A: Browser security restrictions prevent the server from set the names of files to upload.

Reusable jquery dialog

I am using ASP.NET 3.5 with C# 2008.
I want to use a JQuery dialog for showing error message.
For this I need to include a CSS, a JavaScript file into aspx page. Also have to create a <div> with specific Id or class and have to put some buttons like OK, Cancel inside it. Also have to put a label inside <div>. And have to create a <script> block which contains functions to Open or Close the dialog.
All this working fine in single aspx page. But now I want to use this across all the pages and also don't want to make repetitive codes.
So what will be the best way to implement it? Should I put all these stuff inside a user-control and import it into every aspx page where I want to use that dialog? Or any other best way to achieve this?
You can put your javascript code into a js file and add the reference of that js file into your master page then you can call the jquery error dialog into your application.

Dynamically add asp:content to a page

I have one problem. I want to setup master pages in my application. As I have too many aspx pages, I don't want to go to everypage and add asp:content tag in it. I want some dynamic way in which I can look into my page, copying it's html/other asp controls and adding it to dynamically created content template.
I know how to dynamically create content templates. But don't know whether it is possible copying aspx page's html and adding it to content template.
Let's say, In my aspx page's codebehind, on page_PreInit, I am adding following code.
base.AddContentTemplate("WebHeaderPH", new CompiledTemplateBuilder(new BuildTemplateMethod(this.getControl)));
getControl is a method which contain anything (html, text or may load a user control.)
This way, I am adding a content template dynamically.
Now my aspx page contents following code.
<span id="someid" runat="server">blah blah...</span>
Now what I want is, to get this span tag by it's id, and wrap it under asp:content. or may be in the above getControl method.
but putting this span on page, throw following error,
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Either I have to put, asp:content template on the page. but If I do this, then I don't need to create contentTemplate dynamically or keep whole page blank as I am creating contentTemplate dynamically. In both cases, I have to edit all my aspx pages.
Is there a way to get page's html and add it into contentTemplate without any need to edit aspx page?
I'm afraid you have to go step by step manually. It is indeed a design mistake, but it won't take you THAT long to change them all.
I've unfortunately made the same mistake as well and I fixed it by manually editing my pages.

ASP.Net Load Data from another page

i am facing one problem..
I have a page which has some templates related to user..
User use this template to send email..
User can have option to save this template and then he can load the saved templates...
What i want is on click on "Load Template" link. a new page appears which will display all the saved templates for logged in user. this page can contain grid. on select i want to close this load template page. and pass the text data back to previous page. which will display this template into text field. so that user can use saved templates.
How to do this using Asp.Net
You can do this using JavaScript, assuming the template selection window is opened with a call to window.open(). When the template is selected you can communicate and invoke methods (such as passing back the selected template ID) with code similar to this:
window.opener.templateSelected(selectedTemplateID);
window.close();
Here is information about window.opener
I believe that this may be what you're looking for. It's pretty straight forward and is in C#. It is done in .Net as opposed to client side JS.

asp.net mvc Upload File ajax

Hi ive got an mvc form with a fileupload functionality. Ive got an action that accepts an file and extracts thumbnails from it, after which the user can select the images and then proceed to submit the form. How can post the initial file via ajax, bearing in mind, this is not the final submission on the form and I want to retain user input. ie no postback
Thanks
I use the ajaxupload plugin for jQuery. Lots of sample code is provided on the site. From the site:
[The] plugin creates invisible file input on top of the button you provide, so when user clicks on your button the normal file selection window is shown. And after user selects a file, plugin submits form that contains file input to an iframe. So it isn’t true ajax upload, but brings same user experience.
Browsers don't allow the uploading of files via ajax. There are several good workarounds, however.

Resources