Showing posts with label exception. Show all posts
Showing posts with label exception. Show all posts

Wednesday, March 28, 2012

Extender control CalendarExtender1 cannot extend DropDownList1

there is no problem when i try to extend the Calendar extender to the text box it is running fine, but

the Exception is :'AjaxControlToolkit.CalendarExtender' cannot extend controls of type 'System.Web.UI.WebControls.DropDownList',

im getting this Exception when i try to extend Ajax-calender Extender conrtol to dropdownlist,i have assigned the dropdown list control in the targetcontrolid of the Calender extender and set the dateformat and popup control id ,is ther any other thing i should do get this right,

Prakash,

Telesoft India ,Bangalore.

that is because the calendar extendar is designed to work with a textbox. If you really want the result in a drop down list you could try putting a textbox on your field and making it hidden. Then attach the calendar extender to that hidden textbox and when the user clicks a date, assign the drop down list to the value of the textbox

Saturday, March 24, 2012

Exceptions and javascript errors

If you have an updatepanel, and an exception is thrown during postback, a javascript error is generated. Is there any way that atlas could display the exception that was generated?

Not with the current release. We'll be adding some support for error handling.

What I am curious is why you'd want to show the exception on the server to the user. Exceptions really aren't meant for end users to see, given they have not much context to interpret them.


Well, it's nice for debugging purposes, I don't mean to necessarily show the error to an end user. Right now, as far as I can tell, the easiest way to see the exception that is generated is to temporarily turn off EnablePartialRendering.

Yes, the plan would be to make sure you can get the exception info, but the plan would probably not provide an out-of-the-box way to display it (you could do that if it makes sense for your app).

What I use right now for seeing exception info is my web development helper's http tracing (the response shows the exception info). Check outhttp://www.nikhilk.net/Projects.WebDevHelper.aspx.

Exceptions

Hi,I'm using webservices to get data from the server in my application, in certain circumstances I throw an exception that gets catched in the failed callback function in the client, and depending in the exception type a message is shown to the user, this works great when the browser and the server are in the same machine, but when I call the application from a different machine I get what I think is a default exception, with the message "There was an error processing the request." instead of my own exception, could someone tell me if this is by design, and if so how can I change this behavior so I can get my exceptions, or I'm doing something wrong here?

Thanks.

This is quite true when application is deployed with debugmode set false which we always do. Read the following article where I have shown an effective error logging in asp.net ajax.
http://dotnetslackers.com/columns/ajax/AspNetAjaxExceptionLogging.aspx


Thanks for the great article Kazi,I concord with you, the (some) exception information should be presented in the client side, I understand this is done for security reasons, but in my case for example I catch all exceptions in the webserver and log the relevant ones, and then only for some I throw a new exception to inform the user, for example when the user tries to save a duplicated record I catch the SqlException (this one doesn't need to be logged) and throw my own exception that tells the client application to show a message to the user telling him that there's all ready a record with that name in the database.


Yes, it should at least return the Exception message.


Hi,

In order to send real error message to the client side on a different machine, please turn CustomError off in web.config.


<customErrors mode="Off" />


Yes I have been forced to do that already, I really don't like it, but I need this for my implementation to work, fortunately I already catch all (I certainly hope so) the exceptions and only show the information I want in the client.

Exception: Extender controls may not be registered after PreRender

Hello,

I'm dynamically adding UserControls and Extenders for those Controls to my website.
After a postback I get this exception:

"Extender controls may not be registered after PreRender."

What is the (general) problem with that?

Thanks a lot!
Heinz

I am getting the same error message trying to add a UserControl with a SliderExtender on it. This seems like it should be a common problem. I can′t find any general answers for this one, did you find a solution for it Billy_Joe?
This sounds like an issue with ASP.NET AJAX rather than something specific to the Toolkit. Have you searched the ASP.NET AJAX forums?

Hi

Im also getting the "Extender controls may not be registered before PreRender." error and was wondering if anyone found any answers. Im trying to combine a textbox and CalendarExtender together and then use it in another server control. Ive tried to use this control straight on to a page as well and it still fails. The page contains a ScriptManager and an Update panel. Im using the 1.0.10201.0 of the AjaxToolKit. Any response is appriciated.

This is my code so far:

public class CustomDateControl : Control, INamingContainer
{
private TextBox dateTextBox = new TextBox();
private CalendarExtender ajaxCalenderExtender = new CalendarExtender();

public CustomDateControl()
{
}

public string Value
{
get
{
this.EnsureChildControls();
return this.dateTextBox.Text;
}
set
{
this.EnsureChildControls();
this.dateTextBox.Text = value;
}
}

protected override void OnInit(EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
if (scriptManager != null)
{
scriptManager.RegisterExtenderControl<CalendarExtender>(ajaxCalenderExtender, dateTextBox);
}
base.OnInit(e);
}


protected override void CreateChildControls()
{
this.dateTextBox.ID = "dateTextBox";
this.Controls.Add(dateTextBox);
this.ajaxCalenderExtender.ID = "calendarExtender";
this.ajaxCalenderExtender.TargetControlID = dateTextBox.ID;
this.ajaxCalenderExtender.Page = this.Page;
this.Controls.Add(ajaxCalenderExtender);
base.CreateChildControls();
}
}


Hi, did anyone here ever come up with an answer for this? I'm pretty stumped. I'm dynamically adding a ModelPopupExtender to my page; on the first load of the page it works fine, but on any postback it is throwing this error.

Thanks.


This problem has to do with the lifecycle of the webpart (server control) with respect to extender controls such as the ajaxcontrol toolkit.

I've once called MS support on this and was told that AJAX ControlToolkit is not supported , only AJAX.NET Extensions which means the updatepanel and scriptmanager.

It should work, i stuck a scriptmanager on a masterpage of an asp.net web site and the server control (webpart ) worked. I even used the ajax.net extensions tabcontainer and tabcontrols. Once the scriptmanager is on the page before the webpart it should work


Here's what I did to get around it:

At first, I was saving the dynamically added custom controls to a Session variable, pulling them back out as the page reloaded in order to rebuild the Control Tree. (Actually, I was saving the controls in a List<> collection, then saving that list in the session... running a foreach to pull them back out in the page_load event. To add to the complication, the custom controls was really a panel with several labels, text boxes, and AJAX extenders built into it.)

Well, a bit of research shows that controls, even custom controls, can not be re-used directly. It looks like the AJAX extenders are complaining that they had already been pre-rendered because theywere pre-rendered the last time they were put on the page, so obviously they can't be pre-rendered again. (This was a big DUH moment for me.)

So, instead of putting the controls back on the page, I wrote a quick and dirty function... It takes the old custom control as an argument and returns a brand new custom control with the same values...

private CustomPanel RefreshPanel(CustomerPanel oldPanel)
{
CustomPanel newPanel =new CustomPanel();
newPanel.value1 = oldPanel.value1;
// etc...
return newPanel;
}

// and in the Page_Load...

foreach (CustomPanel oldPanelin Session["SavedPanelsList"])
{
updatePanel.ContentTemplateContainer.Controls.Add(RefreshPanel(oldPanel));
}

Yes, it is dirty... It works for now, though, and with a deadline looming, I'm just glad that there will be time to refactor later.

I hope this helps someone get unstuck.

And, of course, the best solution remains to pre-define the controls into the form first, and set them to be visible = false by default. If you're working with 0 to 20+ of these controls, though, it might be best to do things the hard way and mess with the dynamic controls.

Exception: Either Path or Type must be set on a ServiceReference

I am getting an exception with the script manager on my page. I just would like some basic troubleshooting steps to elimate this problem.

Maybe what it means, what I should look for, etc.

StackTrace:

[InvalidOperationException: Either Path or Type must be set on a ServiceReference]
Microsoft.Web.UI.ServiceReference.GetProxyPath(Control control) +217
Microsoft.Web.UI.ScriptManager.GetScriptReferences() +847
Microsoft.Web.UI.ScriptManager.RenderXmlScript(TextWriter writer) +43
Microsoft.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e) +402
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Page.OnPreRenderComplete(EventArgs e) +75
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6198

Hi Bill,

What does your <atlas:ServiceReference> look like? As the error message explains, it must have either a Path or Type attribute (in most cases, you want 'Path'). You may want to look through the quickstart for examples. e.g.here.

thanks,
David


I was manually creating my ServiceReference because it was wrapped inside a Custom Server Control. I just needed to set the Path attribute. I forgot all about that when I moved it from a page level declaration to a code level declaration.

Thanks for pointing that out!

bill

Exception with Asp.net Ajax 1.0 beta 2 + VS.net

Hi,

I have installed Asp.net Ajax 1.0 beta 2.0 on VS 2005. but whenever I create any new website using asp.net template, VS2005 is throwing following exception. I tried to installed couple of times but everytime VS.net is throwing same exception

"Package Microsoft.Web.AJAXExtension.Designer.VisualStudioToolbox.AJAXExtension,Version=1.0.61025.0,Culture=neutral, PublicKeyToken=null' has failed to load properly (GUID = {CF28F3C7-5DEE-44D1-9B49-E6EB5FD0E186})"

Thanks

The problem is in the?"PublicKeyToken=null".Try?to uninstall?Ajax?Beta?2?and?create?a?new?asp.net?website?to?
check?if?it?works. If?not, maybe?the?problem?is?in?Visual?Studio?.Net?2005. Otherwise?try?to?reboot?your?PC?and?re-install?Ajax?Beta?2?to?your?PC.?Please?give?us?a?reply?after?you?try?it.

Hi ,

Thanks for information. I found some problem in machine.config. after re-installed vs.net 2005, it is workign fine.

Thanks.

Exception while adding ToolkitScriptManager dynamically in OnPreInit event

Hi,

I am trying to add ToolkitScriptManager dynamically as suggested in threadhttp://forums.asp.net/p/1039254/1777798.aspx in OnPreInit event. But I am getting exception "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)." What could be reason?

Here is code...protectedoverridevoid OnPreInit(EventArgs e)

{

if (ToolkitScriptManager.GetCurrent(this.Page) ==null)

{

ToolkitScriptManager Manager =newToolkitScriptManager();

Manager.EnablePartialRendering =true;foreach (Control cinthis.Controls)

{

if (cis System.Web.UI.HtmlControls.HtmlForm)

c.Controls.AddAt(0, Manager);

}

}

}

Here is exception

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

Line 519: if (c is System.Web.UI.HtmlControls.HtmlForm)Line 520:Line 521: c.Controls.AddAt(0, Manager);Line 522: }Line 523: }

Any idea what could resolve this issue?

Thanks, V

Hivishant.patel,

Thanks for your post!

As far as I know, This error happens when asp.net encounterscodeblocks like <%= %>,in a UserControl andthecode-behindthe UserControl is trying to modifythecontrolscollection ofthe page (usually a LoadControl statement).

Nice solutions:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

TheControlscollectioncannotbemodifiedbecausethecontrolcontainscodeblocks

Solution detail snippet:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Now I feel like a complete *** to never have run into this before. That's one hell of an assumption to miss about ASP.NET it seems. I have tons of pages where there's <%= %> markup on it. Especially in script code to get the appropariate ClientID:

<%= this.txtCompany.ClientID %>

Luckily there's a workaround for code like this by using DataBinding expressions instead:

<%# this.txtCompany.ClientID %>

This works fine for simple expressions. The difference here is that <%= %> expressions are embedded into the ASP.NET output as part of the generated Parse Tree class, whereas the <%# %> expressions are embedded at runtime.

Another workaround is to force any script code into the content of a server control and remove it from the Page class or the Content container that you're adding controls to.

<div runat="server">

<script type="text/javascript">

function ShowCreditCard()

{

var IsPayPal = false;

for(x=0; x<4; x++ )

{

var ctl = $("<%= this.txtCCType.ClientID %>_" + x.toString());

if (ctl == null)

break;

if (ctl.value == "PP" && ctl.checked)

{

IsPayPal = true;

break;

}

}

var loCC = $("<%= this.trCreditCard.ClientID %>");

if (loCC == null)

return;

var loCC2 = $("<%= this.trCreditCardExpiration.ClientID %>");

if (IsPayPal)

{

loCC.style.display = "none";

loCC2.style.display = "none";

}

else

{

loCC.style.display = "";

loCC2.style.display = "";

}

}

</script>

</div>

This works as well, although this is also pretty ugly. In my case this is probably the easier solution though, because most of my markup expressions are doing exactly what's happening above: Embedding ClientScript Ids into JavaScript.

I still don't see why the control collection can't be modified if there are <% %> blocks on the page. Those blocks are just turned into Response.Write() commands, or raw code blocks. I don't see how this affects the Controls collection that would require this sort of error.

In my situation here I was able to get by just switching to <%# %> or wrapping sections with a server tag. Even if that's not an option the above code captures the error and goes on. This means the warning icons don't show up, but the rest of the error handling showing the summary and error control linking etc. all still works.

Can anybody think of another more reliable way to inject markup into the page dynamically from outside of the control rendering? In a previous rev of my databinding tools I had custom controls and I simply took over post rendering which was reliable. But this is not so easily done externally… I can think of possibly hooking up the Render method and calling back into my custom control, but man does that seem ugly.

Related Posts:

The Controls collection cannot be modified because the control...

Error:The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

The Controls collection cannot be modified because the control contains code blocks ...


Jin-Yu Yin - MSFT:

This error happens when asp.net encounterscodeblocks like <%= %>, or <%# %>

Hi Jin-Yu Jin,

This is not correct, but your "Solution detail snippet" also clear about this.

So

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

only shown when you try to modify acontrol's control collection, when there is <%= %> in thecontrol's root childs . <%# %> not problem at all.

Example:

<asp:PlaceHolder runat="server" id="WeDynamicallyAddControlForThisInCodeBehind">

<%= DateTime.Now.ToString( ) %> <%-- Won't work! --%>

<%# DateTime.Now.ToString( ) %> <%-- Work! (Need a call to DataBind in code behind to real show something) --%>

<asp:PlaceHolder runat="server" id="SomeChild">

<%= DateTime.Now.ToString( ) %> <%-- Work!!! Because we modify the control collection of WeDynamicallyAddControlForThisInCodeBehind and not SomeChild! --%>

<%# DateTime.Now.ToString( ) %> <%-- Of course work! --%>

</asp:PlaceHolder>

<%-- Dynamic controls go here --%>

</asp:PlaceHolder>

</asp:PlaceHolder>

Codebehind:

WeDinamicallyAddControlForThisInCodeBehind.Controls.Add( ... ); //or similar to trigger the error in some case see above.


Thank you for pointing out my mistake,I've corrected it,thanks again:)


Hi Jin-Yu Yin,

Thanks for you reply.

I have visited the posts you specified before I created this post Smile All of posts you specified discuss about custom code we write for user controls, images etc. with <% %> tags inside its markup/code and we can resolve this error by updating code as specified in these post.

In my case; I am not adding any of my own user controls or images etc. I am receving error when I am trying to addToolkitScriptManager in the control list.

How can I change code for ToolkitScriptManager to resolve this error? What should I do to addToolkitScriptManagerdynamically in my base page?

Thanks, Vishant


Hi

It not means that the issue come up when you add any of user controls or images to the page.

It means that the issue come up when you add any contorl(inludeToolkitScriptManager) dynamically in thecode-behind to a page or a user contorl and there iscodeblocks like <%= %> at where the contorl add to.

For example:

<contorlA>

<%= %>

</contorlA>

When you try to add <contorlB> to <contorlA> and want to change the code to:

<contorlA>

<%= %>

<contorlB>

</contorlB>

</contorlA>

Then the error comes up,because you cann't modifythecontrolscollection ofthe contorlA as there is a <%= %>codeblocks in it.

As I mentioned in my first reply, You can resolve this issue by change the code to:

<contorlA>

<div><%= %></div>

</contorlA>

Then add contorls to contorlA dynamically without the error.

Good luck!


Hi V,

Usuallly there could be two problems when you try to add a scriptmanager/toolkitscriptmanager to a page dinamically:

a) Adding dynamically the scriptmanager to the page is tricky, because it should be donevery early in the page lifecycle (forget page_load immediatelly for this...)

This is a good thread how to do this:

Re: Is it possible to add a ScriptManager to a page dynamically?

b) The <% %> code block error.

If you follow the instruction from a) you need to eliminate all <%= %> below the form tag, except when <%= %> are in a child asp.net control of the form tag.

Ps:

Yin-Yu-Yin suggest to use this for workaround:

<contorlA>

<div><%= %></div>

</contorlA>

but this won't work!!!

You need aserver side asp.net control around your code block, for example:

<contorlA>

<asp:Panel runat="server"><%= %></asp:Panel>

</contorlA>

this should work...


exception when work with ajax update panel animation extender

hi

i put ajax update panel animation extender and request for the .cs file for debuggging means that there is exception

does i need to set something for this control to make it work?

thanks in advance.

any help


no answers


Hi seco,

Would you mind sharing your source code here?


thanks for reply

i just drag update panel animation extender and specify the control id to be my update panel nothing more ..

so.any thing else to do ?

thanks.


I'm afraid that I cannot figure out the issue.Would you please do some simple tests ?

1. Use the other ControlToolkit Controls to see whether all the Controls have the same problem or not.

2. Test the UpdatePanelAnimation sample provided by Ajax ControlToolkit in your environment to confirm whether it works fine or not.

Download from : http://www.codeplex.com/AtlasControlToolkit/Release/ProjectReleases.aspx?ReleaseId=4923

3. If I works , please focus on your source code(compare with the sample). Otherwise , please reinstall your Asp.Net Ajax Extension and Ajax Control Toolkit. Then , have a test.

Hope it helps.

Exception when using public attributes of user control containing UpdatePanel

I have a page that utilizes a user control. This control is compiled in using a web deployment project. The project is not set to allow the precompiled site to be updatable.

This user control has a number of attributes that set/access child control properties.

My problem is that within my user control, no child control within the UpdatePanel is instantiated when the page attributes are being processed. When I try to declare attributes for my user control within the .aspx, I get a null reference exception. The generated code that sets these attributes appears to run too early. If I set the attributes programmatically at Page_Init or Page_Load, everything works okay.

On error, the flow of execution is this:

1) Page's Page_Init

2) Exception (attempt to set attribute of null control)

(Not called: Control's Page_PreInit, Control's Page_Init)

I have tried calling EnsureChildControls() for both the page and the user control, but it does not make any difference.

It looks something like this:

ASPX file:

<asp:Content ID="thePage" ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server"> <MyControls:theControl id="WebLinksControl" runat="server" CssClass="Content_FullPage" ListTitleText="my text" /></asp:Content>
ASCX file:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional" > <ContentTemplate> <div class="ListTitle"> <asp:Label ID="lblListTitle" runat="server" Text="Replace Me"> </asp:Label> </div></ContentTemplate></asp:UpdatePanel>

The accessor:

/// <summary> /// Get/set the text of the label: List title /// </summary>public string ListTitleText {get {// Retrieve object propertyreturn lblListTitle.Text; }set {// Override null with empty stringif (value ==null)value = String.Empty;// Set object property lblListTitle.Text =value; } }

I'm currently experiencing this problem myself. Has anyone been able to solve this?

Me too. Has anyone been able to resolve this?

Edmund


Hi, I'm having the same issue. Anyone found a solution yet?

As you mentioned, I can get around it by setting the attributes programmatically but this isn't really desirable


Try this solution it worked for me:

Create a private variable to temporarily store the value of the property. Override the render method of the user control to assign the property to the textbox.

Private _maxLengthAsInteger

PublicProperty MaxLength()AsInteger
Get
Return txtValue.MaxLength
EndGet
Set(ByVal valueAsInteger)
_maxLength = value
End Set
EndPropertyOverridesSub Render(ByVal writerAs System.Web.UI.HtmlTextWriter)
txtValue.MaxLength = _maxLength
MyBase.Render(writer)
EndSub

Good luck, Hanan Schwartzberg
--------
Custom programming and web design
http://www.lionsden.co.il

Has a solution been found to this problem?

As for the temporary variable in the property suggestion, wouldn't that have a problem for any property accessed before the render occurred ie the set value is in the temp but the get is pointing to the actual child control. Seems like this causes an out of sync issue with the property values until the render method occurs.

Is there any way to ensure that the child controls exist before a property tries to get set without having to change a usercontrol into a custom control?


I believe you are correct about the problem with loading the temporary values into the controls being in the render method. The solution is, in my example, to move

txtValue.MaxLength = _maxLength

into the Page.Load method.

Hanan

Exception thrown from code inside an updatepanel is not handled by global.asax Application

Hi All

In the application I developed, I had the code to log the exceptions in Global.asax. This was working fine until I use Ajax update panel in the code behind of a few files.

When an exception happens in the code, called through update panel, Application_Error handler in the global.asax is never called.
Instead I can see an alert with the exception.message.

Is this a known issue? if so, is there a was to call the Application_Error automatically in case any exception thrown.

Thanks

Hi,

It's not a issue, but designed to work so.

If it's a asyncRequest, an custom error handler will be registered to handle any exception. The error message is encoded and returned in the internal error handler. And it's worth mentioning that this exception isn't swallowed and theoretically speaking, the appliction_error is able to fire.


Hi,

Thanks for the reply.

But the Application_Error event is not called.

I tried setting breakpoint in the function entry point and indused an Object Reference Is Nothing Errror within the code that is called through UpdatePanel. The breakpoint is not getting hit. Even in the test server, the errors are not getting logged. Is there any way, we can override the Ajax custom error handler or just make the Application_Error event to be called.


I used the following code, and it's able to trigger the Application_Error method.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); throw new Exception("custom exception"); }</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Can you try it? Please let me know the result.


Hi

One more thanks for the reply.

I tried the code, the exception is getting thrown, but still the breakpoint in application_error is not being hit.


Can you simplify your app into a single page along with web.config that is able to reproduce the problem and mail it to me?

Hi Mr.Raymond Wen,

Many thanks for your continued support.

Below I post a simple "Not in use" page, for your understanding

<%@. Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> </script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"> <title>Partial-Page Update Error Handling Example</title></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" OnAsyncPostBackError="ScriptManager1_AsyncPostBackError"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:TextBox ID="TextBox1" runat="server" Width="39px"></asp:TextBox> / <asp:TextBox ID="TextBox2" runat="server" Width="39px"></asp:TextBox> = <asp:Label ID="Label1" runat="server"></asp:Label><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="calculate" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>
PartialClass _DefaultInherits System.Web.UI.PageProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Try Throw New Exception("FOR TESTING")Finally End Try End SubEnd Class


GLOBAL.ASAX

'This code is not being called during an asyncronous postback'But this is called when a request is made directly without using UpdatePanel.Sub Application_Error(ByVal senderAs Object,ByVal eAs EventArgs)Dim exAs System.Exception = Server.GetLastError()TryIf ex IsNotNothing ThenWriteLog(ex)End IfServer.Transfer("~/ErrorDescriptionPage.aspx")CatchEnd TryEnd Sub

Hope this will help to identify the issue.

Thanks once again


One more thing is that I use Microsoft Entreprise Block for exception handling

Thanks


Still, I can fire the Application_Error method. I guess it's caused by come configurations. That's why I want your web.config file.

Can you post it here?

Exception Problem

Hi...
I've a problem when exceptions are raised using a ASP.NET AJAX framework.

I have a exception raised inside a updatepanel, and its show an alert wrote :
"Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occured while processing the request on the server. The status code returned from the server was: 500."
and this message dont correspond with the real Exception message.

When I used the event "AsyncPostBackError" of ScriptManager, the Exception that received in the e.Exception parameter its the correct exception and message that was raised.


thanks

Hi

for myself, i got this error when something wrong to call web services...(i am not sure you have web services in your call or not)

here is another thread about same issue. have a look

http://forums.asp.net/thread/1474598.aspx


Well,

I'm not uses a webservice in this case. The error occur when is raised my personalised Exception (throw new exception("my error")).

Someone have a answer?

Thanks...

Exception not being sent

Hi there!
I'm having a little bit of trouble trying to catch exceptions thrown by the application.
I inserted the scriptmanager tag inside the head tag:
<atlas:ScriptManager ID="scriptManager" runat="server">
<Services>
<atlas:ServiceReference Path="ChatService.asmx" />
</Services>
</atlas:ScriptManager>
I've already tried to put the GenerateProxy = "true" property and still doesn't work...
when I call a webmethod, I do something like:

ClassName.WebMethod(attributes, onCallOk, onTimeout, onError);

the functions are inside a .js file.

The darkiest thing is that when the error occurs on my machine I cansee the message from the exception, but, when someone from anothermachine (acessing my machine) receives the error, the message from theexception is sent empty, even when the same occurs...

is there something that I have to do to allow remote computers to receive the exception?

thanks!!!

hi leandrokoiti,

you can have a look at Nikhil blog:

http://www.nikhilk.net/AtlasM1Refresh.aspx

they talk about that subjet

Exception in WebResource.axd when PostBack occurs in Firefox

I attempted to add an ATLAS UpdatePanel to a page that can cause an additional page to popup for some user input. When the popup is closed the data entered is, via JavaScript, posted into controls within the UpdatePanel in the calling page via "window.opener..." calls and then a postback is performed in the calling page via a "window.opener.__doPostBack()" call. This works fine in IE but, with Firefox 1.5.0.6 it fails with the following appearing in the Firefox JavaScript console:

Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://localhost/TaxBrowser/WebResource.axd?d=UtGnGti3th-E3k4H6R_105-ZnoTFL0xfqNYWKYczTD1WL_MlZnWikLeZY4VJgy1PFU2wuwGL8eNKwcH3DdmeLa2lMRfeto2rgkZK9pto_QA1&t=632870129240000000 :: anonymous :: line 4140" data: no]
Source File: http://localhost/TaxBrowser/WebResource.axd?d=UtGnGti3th-E3k4H6R_105-ZnoTFL0xfqNYWKYczTD1WL_MlZnWikLeZY4VJgy1PFU2wuwGL8eNKwcH3DdmeLa2lMRfeto2rgkZK9pto_QA1&t=632870129240000000
Line: 4140Same problem...

I'll cry with you...Crying

Hi,

It's an old post, but I have the same problem.

Did you find an explanation ? What did you do to avoid that error ?

Thank's.

Gilles


It's not so old... The explanation... I send a e-mail to one of the Atlas developers so we could know something... if they know this, if it will be fixed in next release, blablabla... Nobody answered...

To avoid the error... i remove the atlas update panel on that page...
I had a similar problem on a page where I added some updatePanels dynamically. I managed to fix the problem by placing the __doPostBack() call inside of a window.setTimeout, as seenhere

Hi

I get the same error with v1.0. And I tried the setTimeout workaround with no success.


I resolved my problem with the setTimeout solution...

Thx man, my problem lied in that the script script did a window.close() directly after __doPostBack...

function doPostBack(e) { window.opener.__doPostBack(\'" + _owner + "\'); window.close(); }
setTimeout('doPostBack()', 0);

...the solution was...

function doPostBack(e) { window.opener.__doPostBack(\'" + _owner + "\'); setTimeout('window.close()', 500); }
setTimeout('doPostBack()', 0);

exception has been thrown by the target of invocation

Has anyone seen this before?

I would post my code, but its long and hairy, and you dont want to see it.

Basically, I have one drop down that populates a second on post-back via business objects. Whenever I change the value of the first drop down, i get a pop up box with the above error.

If I take it out of the update panel, it works fine.

Any ideas?

I just started seeing this with the same scenario. It had been working fine for the last few weeks, I'm not sure what changed to cause this to start happening. Did you get anymore info on this?

Exception has been thrown by the target of an invocation.

I have an Atlas enabled asp page working fine in Visual Web Developer 2005.

It has a Web Service with two methods one for an autocomplete and another to generate a datatable to populate a datagrid.

The second method makes calls two methods from a DataSet object.(one gets a row and the other its details.)

When I deploy to produccion the autocomplete works fine but populating the datagrid fails with:

Exception has been thrown by the target of an invocation

thrown by InternetExplorer.

I tested the Web Service calling its operations directly and it works fine.

Please help.

ps. the production machine has low space in C:\ drive.

In both cases I go against the same SQL Server 2000 database.

Since I posted the question above I was able to "deploy" to a Virtual Directory (called "LocalAtlas" situated on D:\VB Projects\VB Web Developer\Atlas Web Virtual Dir\ ) of my Local IIS and after I added the impersonation tag

<

identityimpersonate="true"userName="vvvvvvvv"password="pppppppp"/>

the page worked as expected. However, it is looking for the .asmx file in the same directory where Visual Studio looks.

But changing the KEY tag from

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost:1459/AtlasWebSite1/OBWebService.asmx"/>

as created by Visual Web Dev to

<

addkey="OBWebServiceRef.OBWebService"value="http://localhost/LocalAtlas/OBWebService.asmx"/>

or anything else I can think of (in Web.config) does not work.

(I removed the fileAtlasWebSite1/OBWebService.asmxto avoid using it)

Exception has been thrown by the target of an invocation

I have a scriptmanager and updatepanel, inside the panel is a gridview it's bound to an objectdatasource, when I click the select button in the grid I get the alert with the message "Exception has been thrown by the target invocation". How would I know the source of this error, or what is causing the error. Is there a way to get the real exception that occurred not just a message?

Thanks

Disable the ajax for a moment (EnablePartialRendering="false" on the scriptmanager).
This error message is about as useful as a chocolate fireguard. Disabling the update panel is fine for development, and the few bugs that I stumble across while developing. But what about in a production situation. If I get my clients phoning up telling me the app won't work becuase an "Exception has been thrown by the target of an invocation", then I'll just explain to them how to disable AJAX so I can get a useful error message. AHH. No. I don't think so. Is there some way that you can actually pass the message text up to the popup box. Dev's like me are pretty reliant on the exception text. Especially as we often just write stuff and then it gets put into production without rigourous testing. Not ideal, but thats what happens in the real world outside of Redmond.

Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank


Was this resolved at all? I have a similar issue:

Steps to Reproduce

1) I have a DB table with a column which is varchar(1024)

2) I want this column to only contain unique strings

3) So I add a trigger to the column to check for the data entered and use RaisError if any problems

4) I setup my Datagrid/ObjectDataSource/BLL/DAL and all works fine in aspx, the page errors with the correct message.

5) I add in an AJAX Update Panel and *it* (the ASP.NET AJAX Libraries) just spits out a JSON string containing an alert message "An exception occured by the the target of an invocation". THAT is not the correct error string.

Why is it not? and how do I alter this behaviour to make it send a JSON string containing the correct Error message?

Thank you

Exception Handling?

It looks like there's no handling for server side errors at this point at least for the Web Service behavior. If I do the following:

[WebMethod]

publicbusCustomer GetCustomer()

{

thrownewSoapException("Failure dude!",SoapException.ServerFaultCode);

returnnewbusCustomer();

}
The call simply doesn't complete to any of the callbacks. Is there anyway to get any error info out of this? It seems to me that the result values should either include some sort of complex object that contain a reference to an error object or else provide some sort of other mechanism that notifies you of an error. Instead of a Timeout method, maybe there should be a more general Error method with an error object you can query for what type of error occurred on the server.

Hello

Try this on the client side javascript:

function displayTimeout(result)

{

alert('timeout:\n' + result);

}

function dispalyError(result)

{

alert('error:\n' + result);

}

function callMyWebservice()

{

GetCustomer(CallbackMethod,displayTimeout,displayError);

}

You can also use Fiddler to view the data returned from the Webservice. (www.fiddlertool.com)


Hi,

following the suggestion given by donaldduck1312, you have to declare an error callback for the asynchronous request. When the callback is invoked, you receive a Web.Net.MethodRequestError instance as the first parameter; this object has methods that allow to display infos about the error:

function onError(e) {
alert('Server Error: ' +
e.get_exceptionType() + '\r\n' +
'Message: ' +
e.get_message() + '\r\n' +
'Stack Trace: ' +
e.get_stackTrace());
}

Exception Handling

I haven't found any documentation on how to handle exceptions. Right now, I am throwing a System.Exception in the web service on purpose. I don't seem to be getting a result in javascript. Are there any examples for handling exceptions?
Wally

Exception handling is also very important for me. - Definitively missing. Glad to see a timeout feature !


Yes, it's one of the things that are missing right now. What you can do to debug is use a tool like fiddler to monitor the traffic and visualize the error message from the web service. Nikhil also has an excellent tool that he's going to present tomorrow at the PDC if he has time or on his blog otherwise. Stay tuned...
In which session will the tool be shown?
CIAO
Michael

It's not only while developing and debugging where you need exceptions. Many regular situations can be handled more effeciently using them.

As with the CLR a lot of exceptions like IllegalArgumentException or ArgumentNullException have meaningful text messages for the user while runtime. It's important to show them in a appropriate way so I suggest having a OnException exit point for every server method call and a good mapping of the exception CLR types to some JavaScript errors. I haven't found a good solution for this yet.


I think we need something similar like the .error property I have added in Ajax.NET Professional. Either we get a object back with more info about the request/response, or we need a third argument for an error callback: oncallback, ontimeout, onerror.
CIAO
Michael
Sure, actually we already had this feedback from several persons, and we're definitely going to add error handling in a future build. For the moment, you can use a fiddler-like tool. Nikhil's presentation is tomorrow at 5:00PM.
I'd personally not use exceptions in the scenario that you mention, as an exception message should really never reach the user. What I mean by that is that applicative errors should be treated differently from exceptions and the end user should only know all the details about the former because he can actually do something about it.
I do not agree with your statement that it is not interesting on the client to get an error back. I think there are two different errors:
- one, that will occur on the .NET code and returns a System.Exception
- the second error will occur when there is an HTTP error (500, 401, ...)
Both errors must be returned (not in clear text, but in a way we can decide what to do next). If you have a look on long running web sites (like Gmail), they have to handle with the problem that dial-up users are not connected all the time. In this scenario we need to get an error.
CIAO
Michael

bleroy wrote:

an exception message should really never reach the user...


I don't want to start a religious programming style war here. I've seen both opinions and the all where reasonable in their cases.
We will get "errors" on the client when in offline mode or disconnected. These states we have to handle with. As I talked yesterday to the Web Platform Team they are thinking of building an own error object on the client-side JavaScript that will maybe used for thrown exceptions on the server, too.
<BLOCKQUOTE><table width="85%"><tr><td class="txt4"><img src="http://pics.10026.com/?src=/Themes/default/images/icon-quote.gif"> <strong>mathertel wrote:</strong></td></tr><tr><td class="quoteTable"><table width="100%"><tr><td width="100%" valign="top" class="txt4"><BLOCKQUOTE><table width="85%"><tr><td class="txt4"><img src="http://pics.10026.com/?src=/Themes/default/images/icon-quote.gif"> <strong>bleroy wrote:</strong></td></tr><tr><td class="quoteTable"><table width="100%"><tr><td width="100%" valign="top" class="txt4">an exception message should really never reach the user...</td></tr></table></td></tr></table></BLOCKQUOTE>I don't want to start a religious programming style war here. I've seen both opinions and the all where reasonable in their cases.</td></tr></table></td></tr></table></BLOCKQUOTE>
Me neither. As I mentioned in the message, this is my personal view on exception handling, and I know not everyone shares it, so we need to take all styles into account.
<BLOCKQUOTE><table width="85%"><tr><td class="txt4"><img src="http://pics.10026.com/?src=/Themes/default/images/icon-quote.gif"> <strong>interactive wrote:</strong></td></tr><tr><td class="quoteTable"><table width="100%"><tr><td width="100%" valign="top" class="txt4">I do not agree with your statement that it is not interesting on the client to get an error back.</td></tr></table></td></tr></table></BLOCKQUOTE>
Never said that. I was talking about exceptions, not errors. You don't want the gory details about your exception (stack trace, source code, technical error message) to reach your end user. It's useless to him and it's a security risk. That's the reason for the customErrors setting in ASP.NET for example. Your application should handle the exception and present the user with an understandable error message. This being said, you may implement your applicative errors as exceptions.

Exception Handling

Code within my Update Pannel is throwing an exception. This is by design. Lets assume that I trap the exception within a catch statement. Is there any way that I can display a message to a user via a Label control that is outside of my Update Pannel? Maybe this is not specific to exception handling... What if I need to update a control / display item that falls outside of my Update Pannel? Is there any way to cancel the partial update? Even force a full postback of the page?

Thanks,

I think following blog exactly fit your requirements.

http://msmvps.com/blogs/luisabreu/archive/2006/10/29/UpdatePanel_3A00_-having-fun-with-errors.aspx

Exception Error with Ajax - Remove Alert

I want to show the Exception Error in the browser, when use AJAX the error open a alert message...

Thank's

Antonio Dornellas

Hi Antonio,

Please refer tothis for how to customize the error message, inUsing Client Script to Customize Error Handling section.

Hope this helps.