Click here to Skip to main content
15,891,567 members

Comments by bobishkindaguy (Top 18 by date)

bobishkindaguy 7-Jul-17 12:44pm View    
I got it working, much appreciated. There were a couple of more things that had to be done so I thought I'd update this with that.

1. I had to add this, as you suggested. It needed to go in the site.master:
"multipart/form-data"

2. I added runat="server" to the "Uploader"markup -- which as you said made it into a "HtmlControls.HtmlGenericControl" in the default.aspx designer code file.

3. Then I had to add the following to the default.aspx markup file. (includes code for providing debug feedback)

<%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>



Dim _cbMessage As String = ""
'Method that processes the callbacks on server.
Public Sub RaiseCallbackEvent(ByVal eventArgument As String) _
Implements System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent

Try
Page.ClientScript.ValidateEvent(Uploader1.UniqueID, Me.ToString())
_cbMessage = "Correct event raised callback."

Catch ex As Exception
_cbMessage = "Incorrect event raised callback."

End Try

End Sub

'Method that returns callback result.
Public Function GetCallbackResult() As String Implements System.Web.UI.ICallbackEventHandler.GetCallbackResult
Return _cbMessage
End Function


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If (Not IsPostBack) Then
Dim CM As ClientScriptManager = Page.ClientScript
Dim CallBackRef As String = CM.GetCallbackEventReference("'" & Page.UniqueID & "'", "arg", "ReceiveServerData", "", "ProcessCallBackError", False)
Dim CallbackScript As String = "function CallTheServer(arg, context) {" & CallBackRef & "; }"
CM.RegisterClientScriptBlock(Me.GetType(), "CallTheServer", CallbackScript, True)
End If
End Sub

Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Page.ClientScript.RegisterForEventValidation(Uploader1.UniqueID, Me.ToString())
MyBase.Render(writer)
End Sub




var value1 = new Date();
function ReceiveServerData(arg, context)
{
Message.innerText = arg;
Label1.innerText = "Callback completed at " + value1;
value1 = new Date();
}
function ProcessCallBackError(arg, context)
{
Message.innerText = 'An error has occurred.';
}
bobishkindaguy 6-Jul-17 18:43pm View    
Okay, I'll get to work on that. Thanks for your patience !
bobishkindaguy 6-Jul-17 18:41pm View    
Deleted
I have been trying to use the one that has this code to save the filename in a label:
onchange... (codeproject deleted the code)

Of course, that saves the name in the label text, but it's not clear to me where the file content goes.
bobishkindaguy 6-Jul-17 18:32pm View    
I agree that the FileUpload control would be the easiest thing to use, but the reason I arrived at this page is for the same reason as the OP. I need to "put some style" on the FileUpload control.

Therefore the stackoverflow page you suggested is great and works fine, but since it doesn't use the FileUpload control, I'm not sure where the file contents are when the postback occurs. The Request.Files has zero files in it.
bobishkindaguy 6-Jul-17 17:48pm View    
I'm new to asp.net. So I need just a bit more help.
I got it browsing fine, and then it displays the filename - nice for the user to confirm that's the one they want to process.
So then I put a "Submit" button on the page, and the user clicks that which gets me to the code behind.
You're saying the submitted page has the actual file "embedded" in it, and all I have to do is get that using HttpPostedFile and save it on the server side, right?
I don't see "Page.HttpPostedFile" or "Session.HttpPostedFile", would you mind posting a code snippet to show how to get the file contents into a variable? My files will be text, so I would probably be carefully converting the object to a string.
I've looked at HttpPostedFile Class in msdn, but there is no code example.