By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

How to Refresh a particular part of a web page ?

Ganesh9u
P: 23
How to Refresh a particular part of a web page ?

Example :
I want to refresh a particular element <div ></div>

in the asp.net page. using Ajax
Oct 13 '08 #1
Share this Question
Share on Google+
15 Replies


acoder
Expert Mod 15k+
P: 16,027
You can access it using document.getElementById() and then set its innerHTML property (or use DOM methods, e.g. appendChild(), replaceChild()).
Oct 13 '08 #2

Ganesh9u
P: 23
You can access it using document.getElementById() and then set its innerHTML property (or use DOM methods, e.g. appendChild(), replaceChild()).
Yes you are right, but when i used this type, it does not works when the page is posted back.

and I must refresh the particular content without postback from the server.
Eg
my code
Expand|Select|Wrap|Line Numbers
  1. if (Request.QueryString["SendRequest"] != null)
  2.         {
  3.             if (Request.QueryString["SendRequest"].Equals("userlist"))
  4.             {
  5.                 GetUserList();
  6.                 Response.End();
  7.             }
  8.             if (Request.QueryString["SendRequest"].Equals("UserData"))
  9.             {                
  10.                 GetIndividualReport(Request.QueryString["d1"], Request.QueryString["d2"], Request.QueryString["user"]);                
  11.                 Response.End();
  12.             }
  13.         }
  14.  
Works well when I refresh.
Oct 13 '08 #3

acoder
Expert Mod 15k+
P: 16,027
Post your Ajax code (using code tags).
Oct 13 '08 #4

Ganesh9u
P: 23
Expand|Select|Wrap|Line Numbers
  1. function GetAgentList()
  2.     {
  3.         var xmlHttp = GetXmlHttp();
  4.             xmlHttp.onreadystatechange=function()
  5.                 {
  6.                 if(xmlHttp.readyState==4)
  7.                   {                      
  8.  
  9.                   DisplayData(xmlHttp.responseText);
  10.                   }
  11.                 }                  
  12.            xmlHttp.open("GET","Report.aspx?SendRequest=userlist",true);  xmlHttp.send(null); 
  13.     }
  14.  
  15.        function DisplayData(info)
  16.              {
  17.                 var data = info.split("*");
  18.  
  19.                 if(data[0] == 'Err')
  20.                 {
  21.                     if(data[1] == 'N')
  22.                     {
  23.                         alert('7 Days is the maximum date range!!');
  24.                     }
  25.                     //document.getElementById('divMsg').innerHTML = data[1];
  26.                 }
  27.                 else if(data[0] == 'Msg')
  28.                 {                
  29.                     //document.getElementById('divMsg').innerHTML = data[1];
  30.                     alert(data[1]);
  31.                 }
  32.                 else if(data[0] == 'Data')
  33.                 {                      
  34.                   document.getElementById('AgentList').innerHTML = data[1];                   
  35.                 }
  36.  
  37.  
  38.              }
Oct 14 '08 #5

acoder
Expert Mod 15k+
P: 16,027
Where do you make the call to GetAgentList()?

Please post code using code tags. Thanks.
Oct 14 '08 #6

Ganesh9u
P: 23
Where do you make the call to GetAgentList()?
When I click a button control form html page. do you understand.
Oct 15 '08 #7

acoder
Expert Mod 15k+
P: 16,027
Yes, can you post the button code (on the client-side [view source] in the browser).
Oct 15 '08 #8

Ganesh9u
P: 23
Expand|Select|Wrap|Line Numbers
  1.  function GetAgentList()
  2.     {
  3.         var xmlHttp = GetXmlHttp();
  4.             xmlHttp.onreadystatechange=function()
  5.                 {
  6.                 if(xmlHttp.readyState==4)
  7.                   {                                                
  8.                   DisplayData(xmlHttp.responseText);
  9.                   }
  10.                 }                  
  11.            xmlHttp.open("GET","Report.aspx?SendRequest=userlist",true);  xmlHttp.send(null); 
  12.     }
Oct 15 '08 #9

acoder
Expert Mod 15k+
P: 16,027
You already posted that. I meant the button code which calls this function onclick.
Oct 15 '08 #10

Ganesh9u
P: 23
[HTML] <img id="btnGenerate" runat="server" alt="Generate Report"
onclick ="PleaseWait();GetAgentList();"
src="Images/generate_report_button.gif" />[/HTML]
Oct 15 '08 #11

acoder
Expert Mod 15k+
P: 16,027
That seems OK, so that leaves the server-side script. If you run the page Report.aspx?SendRequest=userlist directly (without Ajax - type in your address bar), what does it output? Is it what you expect?
Oct 15 '08 #12

Ganesh9u
P: 23
Not like that, It gives output to me, but i refresh it the content in my div tag is lost. And the next time when i execute the same i got the correct result.
Oct 15 '08 #13

acoder
Expert Mod 15k+
P: 16,027
That was only for a test to determine if you're getting the correct output from your server-side code.

I think the best thing would be for you to post the whole code (client-side version), or better still, a link to a test page.
Oct 15 '08 #14

Plater
Expert 5K+
P: 7,872
I am guessing that since the button is also a server control, it causes a postback..which happens AFTER the other javascript is run. So the DIV tag gets refreshed, but a postback occurs and the contents are then lost?
Oct 15 '08 #15

Ganesh9u
P: 23
I am guessing that since the button is also a server control, it causes a postback..which happens AFTER the other javascript is run. So the DIV tag gets refreshed, but a postback occurs and the contents are then lost?
What about view state can i use that ?
Oct 16 '08 #16

Post your reply

Sign in to post your reply or Sign up for a free account.