Showing posts with label basic. Show all posts
Showing posts with label basic. Show all posts

Wednesday, March 28, 2012

Trapping server errors

If an asynchronous call generates an error on the server side, the client displays a Javascript alert box with the basic error message, for instance "Object reference not set to an instance of an object".

Is there any mechanism to trap and react to these errors on the client side, for instance directing them to an error page instead of showing them the alert box?

Mike

You can set in web.config

<customErrors mode="RemoteOnly" defaultRedirect="GenericError.aspx">
</customErrors>

So that client side will be rredirected to GenericError.aspx instead of getting an error...


I think you misunderstand the question. These are server side errors that occur on an AJAX asynchronous postback, rather than a regular postback, so it is not possible to redirect the client by using either the built in ASP.NET custom error page functionality, or by using Response.Redirect.

There must be some mechanism within the AJAX library for me to specify what to do in the case of an exception being raised. Really, all I want to do is, instead of the alert box showing the .NET error message, it should show something generic like "Oops, an error occured".

Can someone tell me how I do this?

Mike


Check this example, might be useful for you .

http://ajax.asp.net/docs/ViewSample.aspx?sref=Sys.Net.ErrorHandlingTutorial%23WebServiceMethodError.aspx

http://ajax.asp.net/docs/tutorials/ConsumingWebServicesWithAJAXTutorial.aspx

Monday, March 26, 2012

trigger event doesnt fire when target control in show/hide panel

I have the following code with the basic required elements to produce the problem:

1<body>2<form id="form1" runat="server">3<asp:ScriptManager ID="ScriptManager1" runat="server" />4<div>5<asp:UpdatePanel ID="UpdatePanel1" runat="server">6<ContentTemplate>7<ajaxToolkit:PopupControlExtender ID="PopupExtender" runat="server" TargetControlID="lbTest"8Position="Right" PopupControlID="buttonPanel">9</ajaxToolkit:PopupControlExtender>10<asp:ListBox ID="lbTest" runat="server" Width="154px"></asp:ListBox>11</ContentTemplate>12<Triggers>13<asp:AsyncPostBackTrigger ControlID="btnAddItem" EventName="Click" />14</Triggers>15</asp:UpdatePanel>16<br />17<asp:Panel runat="server" ID="buttonPanel">18<asp:Button ID="btnAddItem" runat="server" OnClick="btnAddItem_Click" Text="Button" />19</asp:Panel>20</div>21</form>22</body>

The click event is never fired, though the postback occurs.

Any thoughts? Am I doing something "illegal" with the arrangement here? I have a whole form I want to show only in certain circumstances, the results of which should trigger the event to update the main page. How would I do this with Atlas if the given arrangement doesn't work?

TIA, Jeff.

Jeff,

This problem occurs because the PopupControlBehavior's _onClick method calls e.stopPropagation(). That prevents the WebForms.PageRequestManager._onFormElementClick method from getting called. That prevents the asynch postback information from being created correctly. That prevents the asynch postback from working properly.

I believe Ted added the problematic call a long time ago to improve the UI of the PopupControl. I've just pointed him to this thread for more info...

Saturday, March 24, 2012

Trigger stops working after first postback

Hi,

First let me explain the basic situation. I have a page with 2 list boxes (there are more, but for the sake of argument, take 2). The Box A contains a list of items. The Box B contains the list of items chosen by the user. There is an imagebutton that when clicked, moves the selected ListItem from Box A to Box B, and there is another imagebutton that moves a selected item from Box B to Box A.

Pretty straightforward. The list boxes are in separate update panels because they each have other triggers associated with them that are not common to the other. Here is what happens, when the move button is clicked the first time, the transfer works. After that, it's as if there is no postback at all.

Here is how I have it setup:

<

atlas:UpdatePanelID="LeftColPanel"runat="server"Mode="Conditional">
<ContentTemplate>
<asp:ListBoxID="LeftCol"runat="server"Rows="10"Width="140"/>
</ContentTemplate>
<Triggers>
<atlas:ControlEventTriggerControlID="MoveToLeftCol"EventName="Click"/>
</Triggers>

<

asp:ImageButtonID="MoveToLeftCol"runat="server"ImageUrl="pics/left.gif"OnClick="MoveToLeft"/>

and similarly for the second List Box.

What I don't understand is why it works the first time, and not after that? Any help would be appreciated.

Thanks,

i also have the same problem with a gridview
i don't know the solution yet but do you have some strange character in your listbox?
like single quote, or something else

or maybe you already found the solution :)

if yes please let me know

thanks

Wednesday, March 21, 2012

Trouble getting started, please help

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