Auto Refresh Data on Page Using javascript
Auto refresh data on page using javascript
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rahul BansalPosted Apr 29, 2015, 2:06 AM
Aspx page
Time in Seconds
.Cs Code
protected void Page_Load(object sender, EventArgs e)
{
lblTable.Text = DateTime.Now.ToString("F");
if (!IsPostBack) Timer1.Interval = Convert.ToInt32(DropDownList1.SelectedValue) * 1000;
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Timer1.Interval = Convert.ToInt32(DropDownList1.SelectedValue) * 1000;
}
ashok kumarPosted Apr 29, 2015, 1:52 AM
I am not having the fixed interval like "interval=15000"
In my case
I want to set the interval based on the dropdownlist
How can i set the interval? Please help me to fix this issue
Thanks in advance
Rahul BansalPosted Apr 29, 2015, 12:22 AM
Aspx Page:-
.CS Code
protected void Page_Load(object sender, EventArgs e)
{
int i;
if (!IsPostBack)
{
lblTable.Text = "0";
i = Convert.ToInt32(lblTable.Text) + 1;
lblTable.Text = i.ToString();
}
else
{
i = Convert.ToInt32(lblTable.Text) + 1;
lblTable.Text = i.ToString();
}
}
ashok kumarPosted Apr 28, 2015, 8:38 AM
Rahul BansalPosted Apr 28, 2015, 7:14 AM
//Your HTML content or asp Controls
ashok kumarPosted Apr 28, 2015, 6:41 AM
I have a doubt in client side autorefresh concept.
In my code i have one checkbox dropdownlist and grid.If I click the checkbox the grid should be refresh the particular seconds based on the dropdown index select.
I tried the following ways
Using Jquery
$("#Cb_Ajax").on('click', function () {
var $cb = $(this);
if ($cb.is(':checked')) {
var $container = $("#content");
// var $cin=$('#<%= Label22.ClientID %>').val('Date.now.toString()');
var strUser = $("#cc_autorefresh option:selected").text() * 1000;
$container.load(document.URL + ' #content');
// alert(strUser);
var refreshId = setInterval(function () {
var param = new Date();
var param2 = param1.getDate() + '/' + (param1.getMonth() + 1) + '/' + param1.getFullYear() + ' ' + param1.getHours() + ':' + param1.getMinutes() + ':' + param1.getSeconds();
$container.load($('#content').text(param2), strUser);
// $container.load("#content", strUser);
alert(strUser);
})
}
else {
clearTimeout(reloading);
}
});
});
Using Javascript
function checking() {
var chkEnabled = $get('Cb_Ajax');
var timer = $find('Timer1');
var Label = $get('Label22');
var e = document.getElementById("cc_autorefresh");
if (e.selectedIndex > 0) {
var strUser = e.options[e.selectedIndex].text * 1000;
// alert(strUser);
//alert(timer);
timer.set_enabled(chkEnabled.checked && e.selectedIndex > 0 == true);
timer.set_interval(strUser);
if (timer.get_enabled()) {
timer._startTimer();
binddata()
}
else {
timer._stopTimer();
}
}
else
alert("Select the time Interval");
}
BUT both are not working .Please suggest me what can i do furthur
Thanks in advance
Rahul BansalPosted Apr 28, 2015, 6:02 AM
incerase/decrease the content value according to need