Using Fineuploader With Asp.net Webforms. Access To Strict Mode Caller Function Is Censored
I am currently using fineuploader with ASP.NET webforms and am encountering a problem with strict mode in FireFox. ASP.NET webforms has a javascript file (microsoftajaxwebforms.js)
Solution 1:
The workaround according to the jQuery ticket (http://bugs.jquery.com/ticket/13335) is to manually call the event on the client side rather than calling __doPostBack
directly.
$('#Save').trigger('click');
However, if you are trying to trigger a postback from within the client-side event, the trigger
option won't work. Instead, you can use ugly, yet trusty setTimeout
to get out of strict
mode.
$('#Save').on('click', function(e) {
var result = doSomeStuff();
if(result.success) {
window.setTimeout(function() { __doPostBack('Save', '') }, 5);
}
// ...
});
jQuery eventually removed use strict
2 years ago, so upgrading the jQuery (if possible) should also solve the issue.
Solution 2:
As aditional information, there's actually an ASP.NET WebForms VB and ASP.NET MVC C# examples if you need to do stuffs like write to database when uploading the files:
VB example:
Imports System.Data.SqlClient
Imports System.Net
Imports System.IO
Namespace Uploader
Public Class UploadController
Inherits System.Web.Mvc.Controller
<HttpPost()> _
Function Upload(ByVal uploadFile As String) As String
On Error GoTo upload_error
Dim strm As Stream = Request.InputStream
Dim br As BinaryReader = New BinaryReader(strm)
Dim fileContents() As Byte = {}
Const ChunkSize As Integer = 1024 * 1024
' We need to hand IE a little bit differently...
If Request.Browser.Browser = "IE" Then
Dim myfiles As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
Dim postedFile As System.Web.HttpPostedFile = myfiles(0)
If Not postedFile.FileName.Equals("") Then
Dim fnAsString = System.IO.Path.GetFileName(postedFile.FileName)
br = New BinaryReader(postedFile.InputStream)
uploadFile = fnEnd If
End If
' Nor have the binary reader on the IE file input Stream. Back to normal...
Do While br.BaseStream.Position < br.BaseStream.Length - 1
Dim b(ChunkSize - 1) As Byte
Dim ReadLen As Integer = br.Read(b, 0, ChunkSize)
Dim dummy() As Byte = fileContents.Concat(b).ToArray()
fileContents = dummy
dummy = Nothing
Loop
' You now have all the bytes from the uploaded file in'FileContents'
' You could write it to a database:
'Dim con As SqlConnection
'Dim connectionString As String = ""'Dim cmd As SqlCommand
'connectionString = "Data Source=DEV\SQLEXPRESS;Initial Catalog=myDatabase;Trusted_Connection=True;"'con = New SqlConnection(connectionString)
'cmd = New SqlCommand("INSERT INTO blobs VALUES(@filename,@filecontents)", con)
'cmd.Parameters.Add("@filename", SqlDbType.VarChar).Value = uploadFile
'cmd.Parameters.Add("@filecontents", SqlDbType.VarBinary).Value = fileContents
'con.Open()
'cmd.ExecuteNonQuery()
'con.Close()
' Or write it to the filesystem:
Dim writeStream As FileStream = New FileStream("C:\TEMP\" & uploadFile, FileMode.Create)
Dim bw As New BinaryWriter(writeStream)
bw.Write(fileContents)
bw.Close()
' it all worked ok so send back SUCCESS is true!
Return "{""success"":true}"
Exit Function
upload_error:
Return "{""error"":""An Error Occured""}"
End Function
End Class
End Namespace
Post a Comment for "Using Fineuploader With Asp.net Webforms. Access To Strict Mode Caller Function Is Censored"