Ok my problem is that I can't get a basic update panel to function correctly.
Here is what I did:
1) Downloaded and installed ASP.NET AJAX
2) Added a reference to System.Web.Extensions from myexisting ASP.NET application.
3) Copied all the web.config stuff I could find into my own web.config. I can post every web.config change if needed.
4) Created a new form.
5) Added a script manager, an update panel, a button and 2 labels.
6) I put 1 label into the update panel
7) I added an update panel trigger for an asyncpostbacktrigger for Button1 / Click.
8) I put some code in the page load and button click events to write out the current time to the labels.
Now when I run this, the button click doesn't just update the update panel, it does a full postback and page reload.
I tried creating an application from the start using the ajax template, and this exact same code works fine, but I seem unable to ADD the ajax functionality into my existing application.
Any ideas? Any way to narrow down the problem?
Here is the page output from my test page (the one the doesn't work):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title>Untitled Page</title></head><body> <form name="form1" method="post" action="zajax.aspx" id="form1"><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNTE4MDcxODkwD2QWAgIDD2QWBAIBDw8WAh4EVGV4dAUKNjozMzozNSBQTWRkAgcPZBYCZg9kFgICAQ8PFgIfAAUKNjozMzozNSBQTWRkZCbSNxjGnv0oo3s0JvUpWd1OHCwj" /><script src="/ScriptResource.axd?d=WWzAfBI_rdQxam3uQdNeBo6UjgPObu2SaxGwCsecklai8gu7WtIhUsofOWAHTAlPUibAvbb2N8dnhGH5Tlo9L6EdZbxe5NvYcX9AZQ-T0Do1&t=633058483670203504" type="text/javascript"></script> <div> <span id="Label2">6:33:35 PM</span> <input type="submit" name="Button1" value="Button" id="Button1" /> <div id="UpdatePanel1"> <span id="Label1">6:33:35 PM</span> </div> </div> <script type="text/javascript"><!--Sys.Application.initialize();// --></script></form></body></html>
Now when I put the same server side code into an AJAX Template Application, it DOES work, and the page output contains a lot more stuff:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head><title>Untitled Page</title></head><body> <form name="form1" method="post" action="default2.aspx" id="form1"><div><input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /><input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /><input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNTE4MDcxODkwD2QWAgIDD2QWAgIBDw8WAh4EVGV4dAUKNjozNToyNCBQTWRkZNZhuPWbMGlct/IbEepy3VFq4PPN" /></div><script type="text/javascript"><!--var theForm = document.forms['form1'];if (!theForm) { theForm = document.form1;}function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); }}// --></script><script src="/WebResource.axd?d=IGbOu8tbXSYcXb22j2-mVA2&t=632993516188917664" type="text/javascript"></script><script src="/ScriptResource.axd?d=qjtDxogNeiSUKOtmty-j9LOFc00mMzNwj-wep6XL5baMU0VZUYW2HyaCCOXHOI2_3oSO_YCxqyX9CyTLuDTKeyhteOcDGwPlwaJ4N4EDBr41&t=633058483670203504" type="text/javascript"></script><script src="/ScriptResource.axd?d=qjtDxogNeiSUKOtmty-j9LOFc00mMzNwj-wep6XL5baMU0VZUYW2HyaCCOXHOI2_3oSO_YCxqyX9CyTLuDTKe9Vuooudj_iJ62Khwrpdqfc1&t=633058483670203504" type="text/javascript"></script> <span id="Label2">6:35:24 PM</span> <input type="submit" name="Button1" value="Button" id="Button1" /> <script type="text/javascript">//<![CDATA[Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1'], ['Button1'], [], 90);//]]></script> <div id="UpdatePanel1"> <span id="Label1">Label</span> </div> <div><input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgLAh/rhCAKM54rGBo/RxSYDefM+QwfmqDXaIMTc/6Ya" /></div><script type="text/javascript"><!--Sys.Application.initialize();// --></script></form></body></html>
My ASPX page has this:
<%@dotnet.itags.org. Page Language="vb" AutoEventWireup="false" CodeBehind="zAjax.aspx.vb" Inherits=".zAjax" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> <asp:Button ID="Button1" runat="server" Text="Button" /> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel> </form></body></html>
Seems like you are messed up with the web.config file. Take a new AJAX Project and copy the web.config file to replace your existing web.config. If you have made any custom changes to your original web.config file, make them in the new.
Are you adding any AJAX related dll's to the \bin folder? You dont need to add them coz with ASP.NET AJAX 1.0 all the assemblies are installed into GAC.
Thanks
You might also find this handy...I know I did when I found the whole thing was reloading/rebuilding (dynamic controls etc)...it should allow you to establish the type of postback you are getting...
' asynchronous postback?If MyScriptManager.IsInAsyncPostBack =FalseThen' do some stuffEndIf
No comments:
Post a Comment