A fetch ajax page isn’t updating within the fetch area

Last post 08-29-2007 6:15 PM by KaziManzurRashid. 4 replies.

Sort Posts:

  • A fetch ajax page isn’t updating within the fetch area

    08-24-2007, 12:18 PM
    • Member
      6 point Member
    • sathai
    • Member since 01-05-2007, 3:00 PM
    • Posts 15

    Hi! I’m having some limitation problem with ajax page that is fetch from a main ajax updating in a div tag. The fetch ajax is taking over main ajax page. In the asp control is not functioning as AsyncPostback, it’s making a full postback then showing fetch ajax page instant. 

    WebRequest.aspx

    1    <body>
    2        <form id="form1" runat="server">
    3        <div>
    4            <h2>
    5                Using WebRequest</h2>
    6            <asp:ScriptManager runat="server" ID="ScriptManagerId">
    7                <Scripts>
    8                    <asp:ScriptReference Path="WebRequest.js" />
    9                </Scripts>
    10           </asp:ScriptManager>
    11           <table>
    12               <tr align="left">
    13                   <td>
    14                       Request Body:</td>
    15                   <td>
    16                       <button id="Button2" onclick="PostWebRequest('ajax.aspx', 'ResultId0')">
    17                           Make POST Request for .aspx file.</button>
    18                   </td>
    19               </tr>
    20           </table>
    21           <hr />
    22       </div>
    23       </form>
    24       <div id="ResultId0">
    25       </div>
    26   </body>

    WebRequest.js

     
    1    var displayElement;
    2    
    3    function pageLoad()
    4    {
    5        PostWebRequest('ajax.aspx', 'ResultId0')
    6    }
    7    
    8    function PostWebRequest(postPage, HTMLtarget)
    9    {
    10       displayElement = $get(HTMLtarget);
    11       var wRequest =  new Sys.Net.WebRequest();
    12       wRequest.set_url(postPage); 
    13       wRequest.set_httpVerb("POST");
    14       var body = "Message=Javascript generated POST parameter"
    15       wRequest.set_body(body);
    16       wRequest.get_headers()["Content-Length"] = body.length;
    17       wRequest.add_completed(OnWebRequestCompleted);
    18       wRequest.invoke();  
    19   }
    20   
    21   function OnWebRequestCompleted(executor, eventArgs) 
    22   {
    23       if (executor.get_responseAvailable()) 
    24          {  
    25          // displayElement.innerHTML = "";               
    26          if (document.all)
    27             {
    28             displayElement.innerHTML += executor.get_responseData();
    29             }
    30          else // Firefox
    31             {
    32             displayElement.textContent += executor.get_responseData();
    33             }
    34          }
    35       else
    36          {
    37          if (executor.get_timedOut())
    38             {
    39             alert("Timed Out");
    40             }
    41           else
    42             {
    43             if (executor.get_aborted())
    44                   alert("Aborted");
    45             }
    46       }
    47   }
    48   
    49   if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

    ajax.aspx

     

    1    <body>
    2        <form id="form1" runat="server">
    3        <div>
    4            <asp:ScriptManager ID="ScriptManager1" runat="server" />
    5            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    6                <ContentTemplate>
    7                    <asp:Label ID="Label1" runat="server"></asp:Label>
    8                </ContentTemplate>
    9                <triggers>
    10                   <asp:asyncpostbacktrigger ControlID="Button1" EventName="Click" />
    11               </triggers>
    12           </asp:UpdatePanel>
    13           
    14           <br />
    15           <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    16           
    17       </div>
    18       </form>
    19   </body>
    
     

    Ajax.aspx.cs

     

     

    1    public partial class ajax : System.Web.UI.Page
    2    {
    3        protected void Page_Load(object sender, EventArgs e)
    4        {
    5    
    6        }
    7        protected void Button1_Click(object sender, EventArgs e)
    8        {
    9            Label1.Text = "AJAX updated";
    10       }
    11   }
    
    

    Thank you in advance for your help

     

     

    James NW
  • Re: A fetch ajax page isn’t updating within the fetch area

    08-29-2007, 4:50 PM
    • Member
      6 point Member
    • sathai
    • Member since 01-05-2007, 3:00 PM
    • Posts 15

    Does anyone have any ideas?

    Thank you in advance

    James NW
  • Re: A fetch ajax page isn’t updating within the fetch area

    08-29-2007, 5:23 PM
    • Star
      8,978 point Star
    • dwhite
    • Member since 02-08-2007, 2:25 PM
    • Bristol, CT
    • Posts 1,422
  • Re: A fetch ajax page isn’t updating within the fetch area

    08-29-2007, 5:34 PM
    • Member
      6 point Member
    • sathai
    • Member since 01-05-2007, 3:00 PM
    • Posts 15

    Thanks 

    Yap! my solution was base on this example. their posttarget.aspx is my ajax.aspx. problem the updatepanel of the fetched page is not doing ayncpostback.

    James NW
  • Re: A fetch ajax page isn’t updating within the fetch area

    08-29-2007, 6:15 PM
    Answer
    • Contributor
      4,792 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 11:04 AM
    • Dhaka, Bangladesh
    • Posts 882

    There are several reason that it will not works. The Calling page already has a ViewState, EventArgument, EventValidation hidden field. So once you are setting the html of the request page in an div this fields gets dupicated. The Form will never get posts to the requested page as the original form points to a different location.  Your are ended up in a mixed version of both pages. 

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
Page 1 of 1 (5 items)