I’m using a custom control in ASP.NET that handles file uploading for me. The control has a handler in the code-behind using something like this:
Protected Sub UploadFileComplete(ByVal sender As Object, ByVal e As UploadControl.FileUploadCompleteEventArgs) Handles UploadControl.FileUploadComplete
Within that sub, I post back to the server and do some work on the database, but then when I come back, I want JavaScript to register at that point.
However, when I use Page.ClientScript.RegisterClientScriptBlock or ScriptManager.RegisterClientScriptBlock, the scripts don’t load on the page. I need this JavaScript to run and update the page, and to close the upload dialog window. I assume it’s because the page is already loaded.
Does anyone have any good ideas on how to do this?
Alright so turns out it’s like this…
On the server side (code-behind), in the
UploadFileComplete()sub, you can access thatEventArgsvariable by using the methode.CallbackData = [WHATEVER].And then in your javascript, you use this built in client function:
And that
args.callbackDatavariable has whatever you put in via server side. Pretty slick I think! But hard to figure out cause they didn’t have it documented very well.This way, you don’t need to add your own
RegisterClientScriptBlockmethod, because you can pass in anything you want to JavaScript using their built in method.