tags:

views:

39

answers:

3

I have an asp.net application and in the UI I have a jquery plugin called growel. When I detect that someone have changed their account (code behind) I need to call the jquery plugin to display but this is on the client side.

But how is this possible, I cant call jquery from code behind code (C#), has anyone a workaround or am i missing something.

A: 

If you know about it in the code-behind, presumably it's before the page is rendered. A simple solution would be to write the message you want to display in growl into a javascript variable (inside <script type="text/javascript">) inside the page, check for that variable during inside $(document).ready(), and if it's there, then display it in the growl.

James Kolpack
Yes but I need to display the messages throughout the time the page is active rather than just when the page loads. Maybe I could include a timer on the page and reload the page every minute? but that doesnt sound like a good solution :(
Dan
A: 

The client side script would have to ping the server for updates and, if there, display it. You could do that with a timer and an ajax call.

DA
cool, any links for a sample app? I am not familar with ajax calls
Dan
The jquery side is here:http://api.jquery.com/category/ajax/on the .net side, you'd write a page that outputs the format you want to load via AJAX (xml or json, etc.)
DA
A: 

If you can create a page method that exposes the progress, you can do this via a polling ajax call, something like this:

ASP.Net page side:

[WebMethod]
public static string GetProgress()
{
  //Put progress logic here, whatever you need to return/display
  return "Still processing";
  //When finished: return "All Done!";
}

jQuery side:

function updateProgress() {
  $.ajax({
    type: "POST",
    url: "MyPage.aspx/GetProgress",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      $("#statusMsg").text(msg); //Display the message
      if (msg !== "All Done!") //Stop looping when your "completed" comes back
        setTimeout(updateProgress, 1000); //Update status again in 1 second
    }
  });
}

In whatever method you are kicking things off, just call updateProgress() at the end. This is a very lightweight way of doing things, you're making a simple http request sending very little data, not viewstate and all that, and getting back only the response you want.

Nick Craver