Begin and end request in UpdatePanel using jQuery - asp.net

How get Method BeginRequest & EndRequest In UpdatePanel?(in jquery)
function onBeginRequest()
{
//$.blockui;
}
function onEndRequest()
{
//$.unblockui;
}

with(Sys.WebForms.PageRequestManager.getInstance() ) {
add_beginRequest(onBeginRequest);
add_endRequest(onEndRequest);
}
function onBeginRequest(sender, args) {
$.blockUI();
}
function onEndRequest(sender, args) {

you can capture these events
By Sys.WebForms.PageRequestManager.getInstance() this.

Use this code to have no problems with the update panel of your page!
$(document).ready(function () {
// Put your code here
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
// Put your code here
});
prm.add_beginRequest(function () {
// Put your code here
});

Related

AngularJS 1.1.5 $resource.get is not creating XHR request from setTimeout

I have asked this question on the google forum for AngularJS and haven't heard about it until now. Can someone help me understand what is going on here?
I am trying to periodically refresh a resource and it doesn't seem to be working. I have tracked it until the fact that the promise has been obtained from $http service but the XHR request is never created and fired when the method is invoked in setTimeout. However, if I do the same without setTimeout everything seems to be working just fine.
Working JSFiddle: http://jsfiddle.net/hponnu/Z62QN/2/
window.root_module = angular.module("MyApp", ['ngResource']);
function MainController($scope, $resource) {
$scope.buttonClick = function () {
var res = $resource("http://www.google.com");
res.get({}, function (response) {
alert("response");
}, function (err) {
alert("error");
});
}
}
Broken JSFiddle: http://jsfiddle.net/hponnu/H8aEt/10/
window.root_module = angular.module("MyApp", ['ngResource']);
window.count = 0;
function MainController($scope, $resource) {
$scope.buttonClick = function () {
setTimeout(function () {
alert("timeout: " + window.count);
var res = $resource("http://www.google.com");
res.get({},
function (response) {
alert("response: " + window.count);
window.count++;
}, function (err) {
alert("error: " + window.count);
window.count++;
});
}, 1000);
}
}
As you will clearly see in the broken jsfiddle the error alert is not fired for the first request unless a click event is triggered by click on the button again. I have started noticing this from AngularJS 1.1.4
Any ideas/suggestions?
PS: https://groups.google.com/forum/#!topic/angular/t28mazamT0E is the link for the Google groups thread.
You should always use Angularjs's $timeout instead of setTimeout().
function MainController($scope, $resource, $timeout) {
$scope.buttonClick = function () {
$timeout(function () {
...
}, 1000);
}
}

How to Call Pagemethod in Angular js Service

i am new in Angular js.
Static Method in Code Behind
[WebMethod]
public static string GetPracticeLocations()
{
return "[{ id: 1, name: Test AccountName}]";
}
Angular JS Service
appSettings.service('PracticeLocationsService', function () {
this.getPracticeLocations = function () {
var PracticeLocationsData = PageMethods.GetPracticeLocations();
return PracticeLocationsData;
};
});
i want to know how to implement page method in Angular JS.
Any helpful suggustein apricited
Thanks
Probably I'm too late, but you could use defer to call a page method and return a promise,
var getPracticeLocations = function () {
var deferred = $q.defer();
PageMethods.GetPracticeLocations(function (response) {
if (response) {
deferred.resolve({ result: angular.fromJson(response) });
} else {
deferred.resolve({ result: null });
}
},
function (msg, code) {
deferred.reject(msg);
});
return deferred.promise;
};
You want to look at factory() and $http
pseudo code:
angular.factory("PageMethods", ["$http", function($http){
return {
GetPracticeLocations : function(){
return $http.get("/someurl");
}
}
}]);

WORKER undefined

bonsai docs “Communication” section (http://docs.bonsaijs.org/overview/Communication.html) has the following example which runs everywhere, except IE9:
<script src="http://cdnjs.cloudflare.com/ajax/libs/bonsai/0.4/bonsai.min.js"></script>
<div id="movie"></div>
<script>
var movie = bonsai.run(
document.getElementById('movie'),
{
code: function() {
// receive data from the other side
var text = new Text().addTo(stage);
stage.on('message:externalData', function(data) {
text.attr('text', data.nodeData);
});
stage.on('message', function(data) {
if (data.bonsai === 'tree') {
text.attr('textFillColor', 'red');
}
});
stage.sendMessage('ready', {});
}
}
);
// emitted before code gets executed
movie.on('load', function() {
// receive event from the runner context
movie.on('message:ready', function() {
// send a categorized message to the runner context
movie.sendMessage('externalData', {
nodeData: document.getElementById('movie').innerHTML
});
// send just a message to the runner context
movie.sendMessage({
bonsai: 'tree'
});
});
});
</script>
The fist question is: why the following code modification:
<script src="http://cdnjs.cloudflare.com/ajax/libs/bonsai/0.4/bonsai.min.js"></script>
<div id="movie"></div>
<script>
var movie = bonsai.run(document.getElementById('movie'), 'movie.js');
// emitted before code gets executed
movie.on('load', function() {
// receive event from the runner context
movie.on('message:ready', function() {
// send a categorized message to the runner context
movie.sendMessage('externalData', {
nodeData: document.getElementById('movie').innerHTML
});
// send just a message to the runner context
movie.sendMessage({
bonsai: 'tree'
});
});
});
</script>
where movie.js is:
document.getElementById('movie'),
{
code: function() {
// receive data from the other side
var text = new Text().addTo(stage);
stage.on('message:externalData', function(data) {
text.attr('text', data.nodeData);
});
stage.on('message', function(data) {
if (data.bonsai === 'tree') {
text.attr('textFillColor', 'red');
}
});
stage.sendMessage('ready', {});
}
}
throws “WORKER undefined”
Why original code does not work in IE9?

this.get_element() of asp.net ajax is not working in functions I declare

I try to access the element in my own function through this.get_element() but it does not work.
Type.registerNamespace("LabelTimeExtender1");
LabelTimeExtender1.ClientBehavior1 = function(element) {
LabelTimeExtender1.ClientBehavior1.initializeBase(this, [element]);
var testelement=this.get_element();
var timestamp= this.get_element().attributes['TimeStamp'].value;
alert("in constructor");
},
LabelTimeExtender1.ClientBehavior1.prototype = {
initialize: function() {
LabelTimeExtender1.ClientBehavior1.callBaseMethod(this, 'initialize');
setInterval (this.timer,1000);
alert("after");
},
dispose: function() {
//Add custom dispose actions here
LabelTimeExtender1.ClientBehavior1.callBaseMethod(this, 'dispose');
},
timer: function(){
debugger;
var date= new Date(this.timestamp);
var datenow= new Date ();
this._element.innerText=" ";
if(date.getUTCFullYear<datenow.getUTCFullYear)
{
var myelement= this.get_element();
myelement .innerHTML= date.getUTCFullYear.toString();
}
if(date.getUTCMonth<datenow.getUTCMonth)
{
this.get_element().innerHTML=date.getUTCMonth.toString();
}
if(date.getUTCDay<datenow.getUTCDay)
{
this.get_element().innerHTML=date.getUTCDay.toString();
}
if(date.getUTCHours <datenow.getUTCHours )
{
this.get_element().innerHTML=date.getUTCHours .toString();
}
if(date.getUTCMinutes<datenow.getUTCMinutes)
{
this.get_element().innerHTML=date.getUTCMinutes.toString();
}
}
}
LabelTimeExtender1.ClientBehavior1.registerClass('LabelTimeExtender1.ClientBehavior1', Sys.UI.Behavior);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
Here I am trying to access the custom attribute 'TimeStamp' and calcutate the time and assign to the label to show.
Try to invoke your function through delegates.Then you will not have problem with [this] keyword
something like this:
setInterval (Function.createDelegate(this, this.timer),1000)

ASP.NET <Body onload="initialize()">

I am creating an ASP.NET custom control.
I want to set the body onload event of the ASPX page where the control resides.
Please note I cannot rely on the body tag in the ASPX page having runat="server".
any ideas??
Cheers.
Inline javascript! Just incase you can't use jQuery
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function')
{
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
} } }
addLoadEvent(initialize);
link to read http://www.webreference.com/programming/javascript/onloads/
Credits goto http://simonwillison.net/
If you include jQuery in your project you can use this:
jQuery(document).ready(function ()
{
// page load code here
});
You can run these multiple times on a page, ie handy within a control
Try this,
<script type="text/javascript">
window.onload = initialize();
function initialize() {
//your stuff
}
</script>

Resources