Stumbled into another roadblock. Right now I have a page containing Plupload
and a repeater that basically pulls all the uploaded images from database. This page is loaded dynamically in colorbox
.
What I need is for the repeater to update itself when new images is uploaded into the database. I do this by just calling the Repeater and databind it (Repeater1.Databind()). I'm pretty sure the solution lies in Ajax
but I've looked around and have even used them to call a web service but how do you execute a code behind method?
The code behind method that I want to execute is:
Public Sub reBind()
Dim dt2 As DataTable = blOrgLogo.getOrgLogo(userId, False).Tables(0)
If (dt2 Is Nothing) Or (dt2.Rows.Count = 0) Then
' Nothing is returned
Else
repLogoCollection.DataSource = dt2
repLogoCollection.DataBind()
End If
End Sub
One example I saw online state that this can be done use PageMethods
but I can't get it to work with the above mentioned method.
I can't use the ASP.Net Ajax Timer
control as it just doesn't seem to be working when the page is loaded through colorbox. (If anyone have a solution for this it would be awesome as that would simplify everything haha)
Another piece of info that I'm not sure may be of any use is that the repeater is binded in page_load.
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
userId = Session("UserID")
Dim dt As DataTable = blOrgLogo.getOrgLogo(userId, False).Tables(0)
If (Not IsPostBack) Then
If (dt Is Nothing) Or (dt.Rows.Count = 0) Then
' Nothing is returned
Else
Repeater1.DataSource = dt
Repeater1.DataBind()
End If
End If
End Sub
The Plupload javascript:
// Client side form validation
$('#uploader').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function () {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
uploader.start();
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
You will need to use
$.ajax({
type: "POST",
//Location to the webservice or the webmethod
url: "Services/Service.asmx/reBind",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
//on success
},
error: function(ex) {
//on error
}
});
And above your method add [WebMethod(true)]
you may need to find the vb.net equivalant of this as that is what i used for c#.
As for the ajax call im not sure if you have to have the code in a web service I am pretty sure even if it is in a class it will work, you may have to try both.