i am working in c# asp.net2.0.in my oage one gridview is there.in my page load i am populating the values to the gridview.my need is with out using the ajax toolkit and ajax.dll i need to refresh the gridview with database values.for every 30 seconds it
has to hit the database and bind the values to the gridview. how could i achieve this.page should not get refreshed. so the main need is i should not use ajaxtoolkit and ajax.dll please don't ask me why bacause this is the requirement.
is it possible to use XMLHttpRequest for this. how could i achieve the timer logic with calling hte serverside method with the interval of 3o seconds. please if there is any sample code for this please share with me
making impossible into possible is possible when we have determination,dedication,devotion.
i have gridview which has to be auto refreshed every 20 seconds.i am creating browser application and going to sue in microsoft media room simulator. so the simulator will not accept ajax toolkit. the application is purely based on xhtml. so how can
i achieve this with out reloading hte while page. i would like to use xhtmlrequest. not toolkit. i ahve tried the above code.it is not working. so please cna anyone show me some sample code to do this please
making impossible into possible is possible when we have determination,dedication,devotion.
i have gridview which has to be auto refreshed every 20 seconds.i am creating browser application and going to sue in microsoft media room simulator. so the simulator will not accept ajax toolkit. the application is purely based on xhtml. so how can
i achieve this with out reloading hte while page. i would like to use xhtmlrequest. not toolkit. i ahve tried the above code.it is not working. so please cna anyone show me some sample code to do this please
The only way that you could do that without using the AJAX Toolkit and an UpdatePanel would be to populate the table that the Grid renders as manually client-side, which is not only a lot of work, but far too difficult and too much code to ever post here.
Here is a simple example of what you want to do using a basic table tag:
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_httprequest_js4
And this code will execute every 20 seconds.
<script type="text/javascript">
<!--
var g_timerInterval = 20000; // 1000 = 1 second
// Will be called repeatedly, every g_timerInterval...
var g_timerId = window.setInterval('makeAjaxCall()', g_timerInterval);
function makeAjaxCall()
{
// Do the AJAX call to repopulate the Grid here...
// To stop the timer...
//window.clearTimeout(g_timerId);
}
// -->
</script>
I'd suggest rethinking what you are attempting and use the Toolkit and UpdatePanel or just PostBack the page.
hi NC01 Thankns a lot for the reply.i have ty the code which you have shown the link.but it is not working for me. here is the code http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_httprequest_js4 aspx code: <script type="text/javascript"> var xmlhttp;
function loadXMLDoc(url) { xmlhttp=null; if (window.XMLHttpRequest) {// code for IE7, Firefox, Mozilla, etc. xmlhttp=new XMLHttpRequest(); } else if (window.ActiveXObject) {// code for IE5, IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlhttp!=null)
{ xmlhttp.onreadystatechange=onResponse; xmlhttp.open("GET",url,true); xmlhttp.send(null); } else { alert("Your browser does not support XMLHTTP."); } } function onResponse() { if(xmlhttp.readyState!=4) return; if(xmlhttp.status!=200) { alert("Problem retrieving
XML data"); return; } txt="
"; x=xmlhttp.responseXML.documentElement.getElementsByTagName("CD"); for (i=0;i <form id="form1" runat="server"> <div id="copy"> </div> </form> C# code: protected void Page_Load(object sender, EventArgs e) { string path = Server.MapPath("~/sample.xml"); btnGrid.Attributes.Add("onClick",
"loadXMLDoc('" + path + "');"); } so if i ru this page and click the button i a mnot getting any output.it is blank. please help me in this. ang how t orefresh this using the javascript timer.please i am struckig up with this for lonf time. kindly help me
in this.
making impossible into possible is possible when we have determination,dedication,devotion.
so if i run this page and click the button i a mnot getting any output.it is blank. please help me in this. ang how t orefresh this using the javascript timer.please i am struckig up with this for lonf time. kindly help me in this.
making impossible into possible is possible when we have determination,dedication,devotion.
Not sure what your problem is, but I can't help you with that. I would suggest experimenting with the example in the link untill you understand how it works, and what you would need to do to use it in your circumstances.
hi NC01, Thanks for the reply. actually the original requirement is i am doing chat application and going to use that application in microsoft media room.i am creating browser application which has chat logic inside that. i am doing this application and
have to call the web pages in MSTV simulator.so the simulator doesn't support toolkit.it only supports xhtml and ajax(not toolkit).so i hve to refresh the status of the chat users every 10 seconds.but i should not use ajax toolkit. thats why i hve asked help
for xmlhttp. so i think now you can understand my problem. so please help me in this
making impossible into possible is possible when we have determination,dedication,devotion.
hi NC01, Thanks for the reply. actually the original requirement is i am doing chat application and going to use that application in microsoft media room.i am creating browser application which has chat logic inside that. i am doing this application and
have to call the web pages in MSTV simulator.so the simulator doesn't support toolkit.it only supports xhtml and ajax(not toolkit).so i hve to refresh the status of the chat users every 10 seconds.but i should not use ajax toolkit. thats why i hve asked help
for xmlhttp. so i think now you can understand my problem. so please help me in this
Hi,
Did you tried Page Method? It easy, but I'm not sure whether your simulator support or not.
born2win
Member
89 Points
411 Posts
call serverside code in javascript with timer
Feb 18, 2009 11:24 AM|LINK
hi,
i am working in c# asp.net2.0.in my oage one gridview is there.in my page load i am populating the values to the gridview.my need is with out using the ajax toolkit and ajax.dll i need to refresh the gridview with database values.for every 30 seconds it has to hit the database and bind the values to the gridview. how could i achieve this.page should not get refreshed. so the main need is i should not use ajaxtoolkit and ajax.dll please don't ask me why bacause this is the requirement.
is it possible to use XMLHttpRequest for this. how could i achieve the timer logic with calling hte serverside method with the interval of 3o seconds. please if there is any sample code for this please share with me
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: call serverside code in javascript with timer
Feb 18, 2009 11:52 AM|LINK
And what do you think that XMLHttpRequest is? AJAX that's what.
Your only solution is to use AJAX or do a PostBack. Period. Those are the only 2 ways to execute a server-side process from client-side.
NC...
raju dasa
Star
14392 Points
2447 Posts
Re: call serverside code in javascript with timer
Feb 18, 2009 12:25 PM|LINK
Hi,
Try this javascript code: and create a mediator aspx page to handle the ajax and providing the results.
correct the code and use for ur purpose. only inserts gridview row not deleting. Try ur best.
--------------------------------------------------------------
<script language="JScript" type="text/jscript">
function GetXmlHttpObject(handler){
var xmlHttp1 = null;
try
{ xmlHttp1=new XMLHttpRequest(); }
catch (e) {
try { xmlHttp1=new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) {try {
xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { alert("Note: Your browser does not support AJAX!"); }
} }
xmlHttp1.onreadystatechange=handler;
return xmlHttp1; }
function SendXmlHttpRequest(xmlhttp, url) {
xmlhttp.open('GET', url, true);
xmlhttp.send(null); }
var xmlHttp;
function ExecuteCall(url){
try { xmlHttp = GetXmlHttpObject(CallbackMethod);
SendXmlHttpRequest(xmlHttp, url); }
catch(e){} }
function CallbackMethod(){
try { if (xmlHttp.readyState == 4 || xmlHttp.readyState == 'complete'){
var response = xmlHttp.responseText;
if (response.length > 0){
document.getElementById("timeout").innerHTML = response; //--xyz
if (response.indexOf("Server") == -1)
{ Timerd();}
}
} } catch(e){}}
function Timerd()
{ var url = "AJAXService.aspx";
setTimeout("ExecuteCall('" +url + "')", 30000);
</script>
<body onload="Timerd()"> .....
-------------------------------------------
In place of line "xyz", try: // response is comma seperated values from server.
function(response){ var arr=response.split(","); if(arr.length>0){
var newRow = root.all["<%=gridview1.ClientID %>"].insertRow();
for(i=0;i<arr.length;i++){
var oCell = newRow.insertCell();
oCell.innerHTML =arr[i];}}}
-------------------------------------------------------AJAXService.aspx [without any html tags]
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.Expires = -1;
try
{
string tempF = getTempF();
Response.Write(tempF);
}
catch { }
Response.End();
}
private string getTempF()
{
Class2 obj =new class2(); //implement D/B access in this class.
return obj.commaString();
}
}
---------------------------------------------------------------
Happy Coding.
If u got, mark it as Answer.
rajudasa.blogspot.com || blog@opera
born2win
Member
89 Points
411 Posts
Re: call serverside code in javascript with timer
Feb 19, 2009 07:59 AM|LINK
hi friends,
i have gridview which has to be auto refreshed every 20 seconds.i am creating browser application and going to sue in microsoft media room simulator. so the simulator will not accept ajax toolkit. the application is purely based on xhtml. so how can i achieve this with out reloading hte while page. i would like to use xhtmlrequest. not toolkit. i ahve tried the above code.it is not working. so please cna anyone show me some sample code to do this please
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: call serverside code in javascript with timer
Feb 19, 2009 01:08 PM|LINK
The only way that you could do that without using the AJAX Toolkit and an UpdatePanel would be to populate the table that the Grid renders as manually client-side, which is not only a lot of work, but far too difficult and too much code to ever post here. Here is a simple example of what you want to do using a basic table tag: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_httprequest_js4
And this code will execute every 20 seconds.
<script type="text/javascript">
<!--
var g_timerInterval = 20000; // 1000 = 1 second
// Will be called repeatedly, every g_timerInterval...
var g_timerId = window.setInterval('makeAjaxCall()', g_timerInterval);
function makeAjaxCall()
{
// Do the AJAX call to repopulate the Grid here...
// To stop the timer...
//window.clearTimeout(g_timerId);
}
// -->
</script>
I'd suggest rethinking what you are attempting and use the Toolkit and UpdatePanel or just PostBack the page.
NC...
born2win
Member
89 Points
411 Posts
Re: call serverside code in javascript with timer
Feb 20, 2009 04:29 AM|LINK
born2win
Member
89 Points
411 Posts
Re: call serverside code in javascript with timer
Feb 20, 2009 04:32 AM|LINK
sorry for the confusion post
hi NC01 Thankns a lot for the reply.i have ty the code which you have shown the link.but it is not working for me. here is the code http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_httprequest_js4
aspx code:
<html xmlns="http://www.w3.org/1999/xhtml" ><
head runat="server"> <title>Untitled Page</title> <script type="text/javascript">var
xmlhttp; function loadXMLDoc(url){
xmlhttp=
null; if (window.XMLHttpRequest){
// code for IE7, Firefox, Mozilla, etc. xmlhttp=new XMLHttpRequest();}
else if (window.ActiveXObject){
// code for IE5, IE6 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
if (xmlhttp!=null){
xmlhttp.onreadystatechange=onResponse;
xmlhttp.open("GET",url,true);xmlhttp.send(
null);}
else
{
alert("Your browser does not support XMLHTTP.");}
}
function onResponse(){
if
(xmlhttp.readyState!=4) return; if(xmlhttp.status!=200){
alert("Problem retrieving XML data");return;}
txt=
"<table border='1'>";x=xmlhttp.responseXML.documentElement.getElementsByTagName(
"CD"); for (i=0;i<x.length;i++){
txt=txt + "<tr>";xx=x[i].getElementsByTagName("TITLE");{
try{
txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";}
catch (er){
txt=txt + "<td> </td>";}
}
xx=x[i].getElementsByTagName("ARTIST");{
try{
txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";}
catch (er){
txt=txt + "<td> </td>";}
}
txt=txt + "</tr>";}
txt=txt + "</table>";document.getElementById(
'copy').innerHTML=txt;}
</script></
head><
body> <form id="form1" runat="server">
<div id="copy"><
asp:button id="btnGrid" Text="GetCDinfo" runat ="server" /> </div>
</form></
body></
html>c# code:
protected void Page_Load(object sender, EventArgs e){
string path = Server.MapPath("~/sample.xml");btnGrid.Attributes.Add("onClick", "loadXMLDoc('" + path + "');");}
so if i run this page and click the button i a mnot getting any output.it is blank. please help me in this. ang how t orefresh this using the javascript timer.please i am struckig up with this for lonf time. kindly help me in this.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: call serverside code in javascript with timer
Feb 20, 2009 11:54 AM|LINK
Not sure what your problem is, but I can't help you with that. I would suggest experimenting with the example in the link untill you understand how it works, and what you would need to do to use it in your circumstances.
NC...
born2win
Member
89 Points
411 Posts
Re: call serverside code in javascript with timer
Feb 23, 2009 02:49 AM|LINK
hi NC01, Thanks for the reply. actually the original requirement is i am doing chat application and going to use that application in microsoft media room.i am creating browser application which has chat logic inside that. i am doing this application and have to call the web pages in MSTV simulator.so the simulator doesn't support toolkit.it only supports xhtml and ajax(not toolkit).so i hve to refresh the status of the chat users every 10 seconds.but i should not use ajax toolkit. thats why i hve asked help for xmlhttp. so i think now you can understand my problem. so please help me in this
ASP.NET Dev
Contributor
4548 Points
702 Posts
Re: call serverside code in javascript with timer
Feb 23, 2009 03:40 AM|LINK
Hi,
Did you tried Page Method? It easy, but I'm not sure whether your simulator support or not.
Check these
http://www.asp.net/ajax/documentation/live/tutorials/ExposingWebServicesToAJAXTutorial.aspx
http://blogs.visoftinc.com/archive/2008/09/07/ASP.NET-AJAX-Page-Methods.aspx