How to handle async file upload in uploadify? - c#

I have a uploadify plugin on my page and below it I have a description field and a textbox for it. I have submit button below it. Now my problem is uploadify will start async file upload as soon as you select file. I want the uploadify to start upload on click of submit button and also description field's value to be available on the server. I am aware that there is option where you can ask uploadify to start upload on the click of some button. But even if I do that the submit button click event will be fired and the upload will be lost. Should I use script manager and update panel (uploadify should not be inside update panel) so that when submit button click event is fired the page doesn't reset and the uploadify can continue its work. How do you all typically handle this?
Thanks in advance :)

To disable auto start of the file upload, add this setting to the config of the uploadify:
'auto' : false
To submit the values of the form to the server along with file you need to create a separate link or button that gets the data from the form and send it using the uploadifySettings function and then call uploadifyUpload().
Here is an example that will send the details of an MP3 file filled in a form by user.
<a onclick="$('#file_upload').uploadifySettings('scriptData', { 'artist':$('#t_artist').val(), 'album':$('#t_album').val() }); $('#file_upload').uploadifyUpload()" class="greenBtn">START UPLOAD</a>
Where #t_artist and $t_album are the IDs of the input fields in the form.

Related

Check extension of choosing picture in SP 2013 Picture Library

I need to check pictures extension when user has chosen picture and try to upload it into picture library.
I've found the way to edit master page with js script, but i haven't to edit master page. Then i try to use event receiver Adding, but it can't get the name of file or file path. I used:
var file = properties.ListItem.File.Name; //properties.ListItem - returns null
AfterProperties also returns null.
The another way i see is to edit Adding Picture form with js:
I think is's simplest way but i can't found information about it.
Problem: how to set js script to the form (see picture) or how to do such actions with another way
It can be realized with event receiver ItemAdding and with
properties.AfterUrl
The same answered question with code in:
Customizing upload file functionality in SharePoint picture library
In your case, a simple JS form validation will do.
First I would prevent default action of the submit button.
Then, I would analyze the contents of the filename textbox and check the extention. If it's not one of the listed in the validation script, return false + alert "THis file extention is not supported".
Why would you want to use event receiver? It catches the event on server side.

update status text without page reload

I have a web app! I set a status text for users that is shown below the profile picture of the user. Whenever the user updates the status text, the page reloads on button click, and then the new status appears below the picture. Is there a way to prevent this page reloading and still make the status text changed?
On submit, the new status text is inserted/updated into the database table and then on page load, it is fetched.
You can use Ajax,
Place your Update Button and Status TextBox inside a AjaxUpdatePanel
If it's not possible to add both (Update Button and Status TextBox) to a single AjaxUpdatePanel (as your HTML design), add two different Ajax UpdatePanels (to Update Button and Status TextBox) and call yourstatusupdatepanelname.Update(); from Update Button Click event
you can use jquery ajax to do that and it is easy and will not load your page every time you click a the button:
Asp.net Jquery ajax example
you just asign the status again in button click on success execution of sql statement
I think you need to find out using about ajax , postback for this situation.
You can try with Timer_Tick Event

onclick of any link the web user control is loaded without post back

i have a aspx page and in which\
Add Edit Delete
ABC GRIDVIEW
DEF
GHI
on click of any side link let ABC , DEF etc the Gridview related to that is opened
the gridview is in the Web user control and i have to show the gridview in the Placeholder dynamically.
in this case the whole page is not post back only the page in which the grid view is showing is post back and show the result.
please help and suggest me that how is it possible
It seems you are using dynamically lodaed controls. For events to work, you have to recreate your control on everypostback(OnLoad), if not the event won't be fired.
http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic4
If I understand you correctly, you want to Submit the form in 'GRIDVIEW' by clicking on one of the links on the left?
You can trigger submit events through jQuery as follows:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").submit();
});
This will submit the form, but presumably, you'll want to post the form to different locations regarding on which link is clicked?
I would suggest:
$("#ABC_link").click(function(event) {
event.preventDefault();
$("#myForm").get(0).setAttribute('action', 'myCorrectActionValue'); //this works, similar commands tend to fail silently
$("#myForm").submit();
});

File Upload doesn't work in a page with Ajax Update Panel

I am using Ajax File Upload control in ASP.NET 4 using c#. The same page has an update panel too but the upload control is not inside the update panel. The upload control is outside of the update panel.
The update panel has a captcha image and submit button which is described here too. The submit button inside contains code for saving the file from upload control.
The problem is that when user has browsed the fife to be uploaded using upload control and then enters a wrong captcha value and submits, then a new captcha image is given asynchronously to the user for entry. Now the upload control still shows the path in the upload bar for the file, but on the programming side it does not detects the file.
The submit button code:
if (AsyncFileUpload.HasFile)
{
// upload logic and other stuff
}
else
{
// lblShow.Text = "There is no file to be uploaded";
}
The above code for example executes the else part to say "There is no file to be uploaded". The page still hasn't refreshed totally and the file upload control has the path of the file displayed. Kindly help me with this problem.
If your code:
if (AsyncFileUpload.HasFile)
{
// upload logic and other stuff
}
else
{
// lblShow.Text = "There is no file to be uploaded";
}
is in the Page_Load event, it will still execute in the context of a partial post-back, e.g. the UpdatePanel refresh. If a full form submit has not been performed from the browser (you mentioned your File Upload is outside of the UpdatePanel) then the page will not detect the file upload.
What I am confused about is why you have called it AsyncFileUpload when it is outside the UpdatePanel?
EDIT:
Based on your answer, I don't think your Captcha implementation is workable with async file upload as you have it now.
The UpdatePanel does an async POST to evaluate captcha result, but you will not POST the file contents yet because its not inside the UpdatePanel. Then your server-side code evaluates the captcha result and will either return html or a redirect in the async-response back to the browser... somewhere you need to eventually submit the form to get the file.
Unless you're prepared to write code to send some javascript back to your page in the async-response to trigger a full form submit, AND re-evaluate CAPTCHA again on the form submit, you're probably better off taking out the UpdatePanel, in my opinion.
If you are using Ajax update panel with file upload control then you have to add postback trigger into update panel triggers. Like:
<Triggers>
<asp:PostBackTrigger ControlID="btnContactSubmit"/>
</Triggers>

Delete Button issue

I am using one link button in an asp.net application for delete purpose. For the confirmation i added the property of OnClientclick="return ValidateOnDelete();". By Default it works as fine. But i have One condition is that When the user is not admin, the delete button will be disabled. My problem is that, if the user clicks on the delete button when it is in disabled mode, the confirmation message will come. How it can avoid this issue?
pass the button to the ValidateOnDelete() function using
OnClientclick="return ValidateOnDelete(this);"
then within the ValidateOnDelete() function do a test for the button disabled status
function ValidateOnDelete(button) {
if (button.disabled) return false;
}
You could add the javascript on page load
i.e
Page.ClientScript.RegisterStartupScript(typeof({The Wep Page Namespace}), "{Your FunctionName}", "javascript text here", true)
Or create and hidden textbox with a flag
Ie.
And then during the page load set this to 1 if its an admin users
Then refer to this box in your javascript
or add the attribute at page load
i.e
Button1.attributes.add["OnClientclick] = "return ValidateOnDelete();"
Sp

Categories

Resources