Use jquery to fire off my timer
I have a timer on my web app called Timer1 and the enabled = false
. I want to use jquery to fire off my timer. I thought that $("Timer1").enableSelection('True');
would work but it doesnt appear to be working.
Any suggestions here?
Thanks guys!
My jquery code:
var lastupdate;
$(function () {
$.ajaxSetup({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: "{}",
error: function (a, b, c) {
try {
var err = (JSON.parse(a.responseText)).Message;
alert(err);
}
catc开发者_StackOverflow中文版h (ero) {
alert(a.responseText);
}
}
});
// updateSettings();
$("#refreshBaan").click(function () {
$.ajax({
url: "Default.aspx/refreshBaan",
success: function (msg) {
$("#lastBaanUpdate").html("");
$("#lastBaanUpdate").progressbar({ value: 0 });
$("#refreshBaan").attr("disabled", "disabled");
//**
$(function () {
$("Timer1").enableSelection('True');
$("#progressbar").progressbar({ value: 0 });
setTimeout(updateProgress, 200);
});
function updateProgress() {
var progress;
progress = $("#progressbar")
.progressbar("option", "value");
if (progress < 100) {
$("#progressbar")
.progressbar("option", "value", progress + 2);
setTimeout(updateProgress, 200);
}
}`
My C#:
<asp:Timer ID="Timer1" runat="server" Interval="17000"
ontick="Timer1_Tick" Enabled="False" />
$("Timer1")
is not a valid selector. It should be referencing an HTML tag, class or id.
ex: $("div")
or $("#Timer1")
o r $(".Timer1")
.....and so on.
I really need to see some code... but it looks like this could do the trick:
$('#Timer1').removeAttr('disabled');
Any tag with the text runat="server"
in it is a server-side tag which cannot be directly manipulated via javascript the way you are attempting to do here.
A timer itself is an AJAX control that's implemented client-side by javascript emitted by the Timer ASP.Net class's Render function, which causes a postback to happen at the specified interval.
By looking at System.Web.Extensions.dll (the assembly the System.Web.UI.Timer class is housed in) in Reflector, it references 'MicrosoftAjaxTimer.js', which is included in the embedded resources section of the DLL. In this file, there appears to be a function named Sys.UI._Timer.set_enabled() which would appear to do what you want.
Keep in mind though you are using the implementation details here directly and these are subject to change at any time by Microsoft. I'd recommend not using JQuery at all, but manipulating the Timer object server-side instead.
精彩评论