Reputation: 194
I've already searched the internet and try different approaches but I'm having a really hard time to make it work. I'll accept any help, involving third parts components, javascript and everything... My problem (I think) is that I'm not using an Upload button but a button that also save a data form. Markup:
<div id="divInserimento" runat="server" class="contact-form scrollDiv">
<div>
<asp:TextBox runat="server" ID="txtTitolo" placeholder="Titolo nota" CssClass="input_text" MaxLength="1000"></asp:TextBox>
</div>
<div>
<asp:TextBox runat="server" ID="txtNota" placeholder="Nota" CssClass="input_text" TextMode="MultiLine" Height="10em"></asp:TextBox>
</div>
<div style="padding: 3px; background-color: whitesmoke; border: 1px solid black;">
<asp:FileUpload runat="server" ID="MyFileUpload" Width="100%" />
<asp:HiddenField runat="server" ID="hdnNomeFile" />
</div>
<p> </p>
<table border="0" cellspacing="0" cellpadding="0" style="width: 100%">
<tr>
<td align="left">
<asp:Button runat="server" CssClass="gbutton" ID="btnAnnullaIns" Text="Annulla" UseSubmitBehavior="false" OnClick="btnAnnullaIns_Click" />
</td>
<td align="right">
<asp:Button runat="server" CssClass="gbutton" ID="btnConfermaIns" Text="Conferma" OnClick="btnConfermaIns_Click" UseSubmitBehavior="false" />
</td>
</tr>
</table>
</div>
Code behind:
Function Upload()
Dim file As String = ""
If MyFileUpload.HasFile Then
If MyFileUpload.PostedFile.ContentLength <= 15000000 Then
'throbber.Style("display") = "normal"
Dim path As String = My.Settings.pathUpload1 & rfCliente & My.Settings.pathUpload2
If Not Directory.Exists(path) Then
'If Directory (Folder) does not exists. Create it.
Directory.CreateDirectory(path)
End If
file = path & MyFileUpload.FileName
MyFileUpload.SaveAs(file)
hdnNomeFile.Value = file
ClientScript.RegisterStartupScript(Me.GetType(), "Scriptkey", String.Format("alert('{0}');", "File caricato: " & MyFileUpload.FileName), True)
If MyFileUpload.FileName.Contains(".txt") Then
Dim srRead As New System.IO.StreamReader(file)
Dim strFileText As String = ""
strFileText = srRead.ReadToEnd
srRead.Close()
txtNota.Text = strFileText
txtTitolo.Text = MyFileUpload.FileName
End If
Return True
Else
hdnNomeFile.Value = ""
ClientScript.RegisterStartupScript(Me.GetType(), "Scriptkey", String.Format("alert('{0}');", "Errore nel caricamento"), True)
Return False
End If
'throbber.Style("display") = "none"
Else
ClientScript.RegisterStartupScript(Me.GetType(), "Scriptkey", String.Format("alert('{0}');", "Il file supera le dimensioni massime consentite (15mb)"), True)
Return False
End If
End Function
The function "Upload" is called by pressing the btnConfermaIns button as follow:
If MyFileUpload.HasFile Then
If Upload() Then
inserimentoNota()
Else
ClientScript.RegisterStartupScript(Me.GetType(), "Scriptkey", String.Format("alert('{0}');", "Errore nel caricamento"), True)
End If
Else
inserimentoNota()
End If
Thank you all
Upvotes: 0
Views: 1129
Reputation: 539
If I understood correctly you want to show a "wait" message while the file is uploading.
You can accomplish this using javascript:
<asp:Button runat="server" CssClass="gbutton" ID="btnConfermaIns" Text="Conferma" OnClick="btnConfermaIns_Click" UseSubmitBehavior="false" OnClientClick="showWaitingMessage()" />
<div id="waitMessage" style="display: none;">Please wait...</div>
<script>
function showWaitingMessage() {
document.getElementById("waitMessage").style.display = "block";
}
</script>
Upvotes: 1