PDA

View Full Version : Doubts using Ext.MessageBox



franklt69
1 Mar 2007, 7:16 PM
Hi I would like to show the error from server in a Ext.MessageBox but I don't know how I can fill the textArea using multiline, a liltle help please.

Using Ext.MessageBox.alert('Status', resp.responseText); appear the error but I can't close this windows becouse the error text is big and the close button disapear.



I am doing it:

function responseFailure(resp){
//alert(resp.responseText);
//debugger;
//Ext.MessageBox.alert('Status', resp.responseText);
Ext.MessageBox.show({
title: 'Error',
msg: 'Please send it support:',
width:300,
buttons: Ext.MessageBox.OK,
multiline: true,
textboxEl: resp.responseText

});
}

kind regards
Frank

JeffHowden
1 Mar 2007, 7:28 PM
Using alpha2 rev6, I'm unable to reproduce this problem. Which one are you using?

franklt69
2 Mar 2007, 5:32 AM
Yes I am using alpha2 rev6, when I get a error from server (asp.net) it response with an aspx page, in my case I get the error from server in resp.responseText, it appear in the Ext.MessageBox.alert with yellow color in error ect.. like appear in an aspx page with error, but it has many text and disapear the close button, I would like show the error inside textArea in a multi-line prompt dialog, becouse it have scroll bar but I don't know how set the resp.responseText to textArea inside multi-line prompt dialog, I like the alert becouse it show the resp.responseText with color (like a html page), but don't have scroll bar and only has a button OK. Is there some dialog where I can show the error with scroll, and add for instance a button to send error for mail I mean (show the error and appear Send Error button)?

kind regards
Frank

maerteijn
2 Mar 2007, 5:39 AM
Setting HTML inside a textarea will have the effect that the HTML is not shown rendered anymore. You better put the ASP error inside a div element, and then set the css property overflow:auto, so it will have a scrollbar.

Could you post a screenshot BTW, your description of the problem is very unclear.

JeffHowden
2 Mar 2007, 12:02 PM
Yes I am using alpha2 rev6, when I get a error from server (asp.net) it response with an aspx page, in my case I get the error from server in resp.responseText, it appear in the Ext.MessageBox.alert with yellow color in error ect.. like appear in an aspx page with error, but it has many text and disapear the close button,[...]

Well, I guess the question then, is how much text are you getting back? Can that text be paired down to the bare essentials? And, is that text an entire HTML document with doctype, html tag, head tag, body tag, etc? If so, that's just not going to work like you want it to. In order to include it in the dialog, it must be an HTML fragment, not a complete HTML document.

franklt69
2 Mar 2007, 3:45 PM
more clear , I am doing it:

I send a xml to server, I parsed it and update the database, if there is an error in this proccess I catch the exception and send it to client, then I want to show it to user, but if I try with alert the exception from server has many information and the button close in the dialog go up and don't appear in the browse, so the doubt can I use some Ext.MessageBox dialog to show the client or I have to do my dialog?


using a multi-line prompt dialog the error don't appear in html format but i can read it using scroll how I can add the error to textArea in multi-line prompt dialog?

example the a exception send from server



<html><head><title>Object reference not set to an instance of an object.</title>


<style>
body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
</style></head><body bgcolor="white">

<span><h1>Server Error in '/ASFA' Application.<hr color="silver" size="1" width="100%"></h1>

<h2> Object reference not set to an instance of an object. </h2></span>

<font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

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.NullReferenceException: Object reference not set to an instance of an object.



Source Error:



<table bgcolor="#ffffcc" width="100%">
<tbody><tr>
<td>
<code></code><pre>
Line 42: public XmlToDb(string Id )
Line 43: {
<font color="red">Line 44: Attributes.Add("throw an error");
</font>Line 45: Attributes = new ArrayList();
Line 46: Values = new ArrayList();</pre>

</td>
</tr>

</tbody></table>




Source File: c:\projectest\WebSite\XmlToDb\XmlToDb.cs Line: 44




Stack Trace:



<table bgcolor="#ffffcc" width="100%">
<tbody><tr>
<td>
<code></code><pre>
[NullReferenceException: Object reference not set to an instance of an object.]
WebSite.XmlToDb..ctor(String Id) in c:\projectest\WebSite\XmlToDb\XmlToDb.cs:44
WebSite.HandlerXmlToDb.ProcessRequest(HttpContext context) in c:\projectest\WebSite\XmlToDb\HandlerXmlToDb.ashx.cs:67
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute() +179
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +87

</pre>

</td>
</tr>
</tbody></table>




<hr color="silver" size="1" width="100%">

Version Information:Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

</font>

<!--
[NullReferenceException]: Object reference not set to an instance of an object.
atWebSite.XmlToDb..ctor(String Id) in c:\projectest\WebSite\XmlToDb\XmlToDb.cs:line 44
atWebSite.HandlerXmlToDb.ProcessRequest(HttpContext context) in c:\projectest\WebSite\XmlToDb\HandlerXmlToDb.ashx.cs:line 67
at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
--></body></html>

kind regards
Frank

aefitzhugh
2 Mar 2007, 4:37 PM
If you are getting back a full HTML page as the response, try displaying it in an iframe. If you inject XML containing an HTML element into a subelement of your page it can really confuse your browser.

JeffHowden
2 Mar 2007, 6:34 PM
Alright franklt69, I need you to go back and reread my previous reply. I specifically said that you weren't going to get things to work properly if you are injecting HTML that contains a doctype, html tag, head tag, or body tag into your dialog.

Rather than an alert, you're going to have to take that build a basic dialog with an iframe, take the response from the server, and inject that into the iframe's DOM.

What might be easier is trimming down the response the server sends to something that's just an HTML fragment.

franklt69
7 Mar 2007, 6:20 AM
Hi I need some help about how inject html into a Iframe


when in the server (asp.net) there is an error it response with a html like the code post above, then I am doing it

function responseFailure(resp){

showError(resp.responseText);

}


showError: function(aError){
if(!dlgError){ // lazy initialize the dialog and only create it once
dlgError = new Ext.LayoutDialog("dlg-error", {
modal:true,
width:800,
height:400,
shadow:true,
minWidth:300,
minHeight:300,
proxyDrag:true,
title: 'Error Windows',
shadow:true,
center:{alwaysShowTabs:true},
north: {
split:false,
initialSize: 25

},

center: {
autoScroll:true,
tabPosition: 'top',
closeOnTab: true,
alwaysShowTabs: false
}
});
dlgError.addKeyListener(27, dlgError.hide, dlgError);
dlgError.addButton('Send', dlgError.hide, dlgError);
dlgError.addButton('Dont Send', dlgError.hide, dlgError);

var layout = dlgError.getLayout();
dlgError.beginUpdate();
debugger;
var iframe = Ext.DomHelper.append(document.body,
{tag: 'iframe', frameBorder: 0});
iframe.innerHTML = aError;
feedPanel = new Ext.ContentPanel(iframe, {fitToFrame:true, autoScroll:true, closable:false});
layout.add('center', feedPanel);
dlgError.endUpdate();
}

dlgError.show();
}


the doubt is how I can inject the html (aError) into an iframe ?

kind regards
Frank

tryanDLS
7 Mar 2007, 8:34 AM
Why are you allowing the server exception to just dump back to a generic error page? You should catch the exception in your aspx page and build a simple reponse string from the exception properties (e.g. Message, Stacktrace, InnerException, etc). Then pass that back without all the html and use that as the content of your dialog body. The way you're doing it now, it appears that the error is not being caught and just output via the standard .Net error page.

brian.moeskau
7 Mar 2007, 9:50 AM
Tim is right -- this is a server-side error message that should not be sent back to the client like this since .NET adds the generic error page HTML when it builds its default response. As Tim said, catch the error on the server side, and return only the text of the error as your result.

franklt69
7 Mar 2007, 12:22 PM
I am Agree with both, I should be send from server only the text of the error as result, but this dialog will be useful when I am developing, becouse I can watch the complete error.

Now I don't know how to send an error from server using YAHOO.util.Connect

I did it

server side:

try
{
Stream requestStream = context.Request.InputStream;
using( StreamReader sr = new StreamReader(requestStream, System.Text.Encoding.UTF8))
{
dosomething();
context.Response.Write(result);

}
}

catch (Exception e)
{
throw
}

in this way always I get the error (complete html) in the client

var hcallback={
success: saveSucess,
failure : responseFailure
};

YAHOO.util.Connect.asyncRequest('POST', "/Handler.ashx", hcallback, xmlSearch)

function responseFailure(resp){
Ext.MessageBox.alert('Status', resp.responseText);

}

now I change to:

try
{
Stream requestStream = context.Request.InputStream;
using( StreamReader sr = new StreamReader(requestStream, System.Text.Encoding.UTF8))
{
dosomething();
context.Response.Write(result);

}
}

catch (Exception e)
{
throw new Exception("my error");
}

and again in the MessageBox is the complete html page error


doing that:

try
{
Stream requestStream = context.Request.InputStream;
using( StreamReader sr = new StreamReader(requestStream, System.Text.Encoding.UTF8))
{
dosomething();
context.Response.Write(result);

}
}

catch (Exception e)
{
context.Response.Write("error");
}
Never in the client the function responseFailure(resp) is trigger, so a little help about using YAHOO.util.Connect and raising my error from server.


kind regards
Frank

brian.moeskau
7 Mar 2007, 12:31 PM
If you are doing everything in Page_Load on the server, you will have to end the response stream by doing a Response.End(), otherwise the server page lifecycle will still run to completion and you'll get the entire error page HTML as your response. Here's what my code looks like:


String resp = "Error msg...";
Response.Write(resp);
Response.End(); // <-- make sure you have this!
One other thing, you can still get the same info that the default error page shows you as long as the text you return includes the exception stack trace. Generally, I use ex.ToString() as that includes the stack trace and any inner exception message.

franklt69
7 Mar 2007, 2:17 PM
Thanks, I am using a IHttpHandler and I set it
try
{
Stream requestStream = context.Request.InputStream;
using( StreamReader sr = new StreamReader(requestStream, System.Text.Encoding.UTF8))
{
dosomething();
context.Response.Write(result);

}
}

catch (Exception e)
{
context.Response.Write("error");
context.Response.End();
}

and never the event in the client
function responseFailure(resp){
Ext.MessageBox.alert('Status', resp.responseText);

}
is trigger, why? I am missing something?

kind regards
Frank

tryanDLS
7 Mar 2007, 3:25 PM
Did you look at firebug to see if the response was getting back to the client? What determines whether your flow goes thru your responseFailure function vs your responseOK function? Are you looking at a status code/or something in the response?

brian.moeskau
7 Mar 2007, 3:30 PM
Also, have you stepped through Visual Studio as well to make sure the server code is doing what you expect? You can attach VS to the thread that your browser is using and set a break point and it will stop in the server even when you do an Ajax call (if everything is setup correctly). I often set BPs in both VS and Firebug so that I can stop at various points on the client and server both, depending on where the issue is. Sounds like you really need to step through the entire process and understand what your code is doing a little bit better.

franklt69
7 Mar 2007, 4:53 PM
Hi I am debugging with Firebug and VS in the server, it is an example:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;

namespace WebSite
{
/// <summary>
/// Summary description for Handler1.
/// </summary>
public class Handler1: IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}

public void ProcessRequest(HttpContext context)
{
try
{
Stream requestStream = context.Request.InputStream;
using( StreamReader sr = new StreamReader(requestStream, System.Text.Encoding.UTF8))
{
if (context.Session["aStaffId"] != null)
{

Attributes.Add(""); //here will get an exception
Attributes = new ArrayList();
string result = "all ok";
context.Response.Write(result);
}
}
}

catch (Exception e)
{
context.Response.Write("error");
context.Response.End();
}
}
}
}


In client:

var hcallback={
success: saveSucess,
failure : responseFailure
};

YAHOO.util.Connect.asyncRequest('POST', "/Handler1.ashx", hcallback, xmlSearch)

function responseFailure(resp){
debugger;
Ext.MessageBox.alert('Status', resp.responseText);

}


in Attributes.Add(""); will get an exception because I am using the array before create it then the debug go to catch, if I set in catch
catch (Exception e)
{
context.Response.Write("error");
context.Response.End();
}

I watch in firebug tab response the string "error" but the function responseFailure never is triggered

if I set
catch (Exception e)
{
throw;
}

I watch in firebug in tab response I get the complete html page error, and it appear in Ext.MessageBox so the doubt how I from the server can write an error and it trigger the responseFailure in client?


kind regards
Frank