1

I have an ASP.NET MVC Page with a button called "Start Live Meeting".

When the User clicks on this button, it calls a controller method called "StartLiveMeeting" that returns a string.

If the controller returns empty string, then i want the Timer to call the Controller method until it returns the string. I am using jquery.timer.js plugin ( http://plugins.jquery.com/files/jquery.timers-1.2.js.txt )

On the button click, the controller method is being called. But Timer is not initiating. I have specified 5sec to call the controller method.

I appreciate your responses.

Code on ASPX Page:

//When "Start Meeting" button is clicked, if it doesn’t return empty string, Display that text and Stop Timer. Else call the Timer in every 5 sec and call the StartLiveMeeting Controller method.

$("#btnStartMeeting").click(function() {
    var lM = loadLiveMeeting();
    if (lM == "") {
        $("#btnStartMeeting").oneTime("5s", function() {
        });
    } else {
        $("#btnStartMeeting").stopTime("hide");
    }
    return false;
});
function loadLiveMeeting() {
    $("#divConnectToLive").load('<%= Url.Action("StartLiveMeeting") %>', {}, function(responseText, status) {
        return responseText;
    });
}

<asp:Content ID="Content2" ContentPlaceHolderID="cphMain" runat="server">

<div id="divStartMeetingButton"><input id="btnStartMeeting" type="submit" value="Start Meeting" /> 
           </div>
           <div id = "divConnectToLive">
               <div id="loading" style="visibility:hidden"> 
                    <img src="../../img/MedInfo/ajax_Connecting.gif" alt="Loading..." />
               </div>
           </div>

Controller Method:

[HttpPost]
    public string StartLiveMeeting()
    {
        int intCM_Id = ((CustomerMaster)Session["CurrentUser"]).CM_Id ;
        var activeMeetingReq = (from m in miEntity.MeetingRequest
                                where m.CustomerMaster.CM_Id == intCM_Id
                                && m.Active == true
                                select m);

        if (activeMeetingReq.Count() > 0) 
        {
            MeetingRequest meetingReq = activeMeetingReq.First();
            return "<a href='" + meetingReq.URI + "'>" + "Connect to Live Meeting</a>"; 
        } else {
            return ""; 
        }
    }

1 Answer 1

1

The load() method is asynchronous, so you'll either need to make it synchronous, or put your response logic in the callback.

$("#btnStartMeeting").click(function() {
    loadLiveMeeting();
    return false;
});
function loadLiveMeeting() {
    $("#divConnectToLive").load('<%= Url.Action("StartLiveMeeting") %>', {}, function(responseText, status) {
        if (responseText == "") {
            $("#btnStartMeeting").oneTime("5s", function() {
                 // call load meeting again
            });
        } else {
            $("#btnStartMeeting").stopTime("hide");
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.