PDA

View Full Version : [CLOSED] Ajaxevent always call failure



petherson
Sep 23, 2008, 10:27 AM
I've got a problem when I was trying to post something with a coolite button, my response is always failure, why?
I really want to know why.
Thanks for your help.


<ext:Button ID="btnCadastrarModificar" runat="server" Text="Cadastrar ou Modifica" AutoPostBack="false">
<AjaxEvents>
<Click OnEvent="btnCadastrarModificar_Click" Success="testeRepostaSim" Failure="testeRepostaNao"></Click>
</AjaxEvents>
</ext:Button>

geoffrey.mcgill
Sep 23, 2008, 10:46 AM
Hi petherson,

I think you're going to have to post a simplified .aspx code sample demonstrating how to reproduce this problem.

petherson
Sep 23, 2008, 11:59 AM
Hello, thanks for your answer, this is the required code:


<%@ Page Language="C#" AutoEventWireup="true" %>

<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>

<!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 btnCadastrarModificar_Click(object sender, Coolite.Ext.Web.AjaxEventArgs e)
{
bool modifica = Convert.ToBoolean(this.txbChange.Text);
string response;
if (modifica)
{
response = "Response1";
}
else
{
response = "Response2";
}
this.Response.ClearContent();
this.Response.Write(response);
this.Response.Flush();
this.Response.Close();
}

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ajax Event</title>
<script language="javascript" type="text/javascript">

function testeRepostaSim(resp,conn)
{
alert("Post is working");
}
function testeRepostaNao(resp,conn)
{
alert("Post is not working");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ssssw" runat="server"></ext:ScriptManager>

<div id="saida" runat="server">
<ext:Window ID="Window1" runat="server"
Title="Window Test"
Width="50" Height="50" Center&#111;nload="true">
<Content>
<ext:TextField Hidden="true" HideMode="Display" ID="txbChange" runat="server" Text="false"></ext:TextField>
<div style="margin:20px 60px;">
<ext:Button ID="btnCadastrarModificar" runat="server" Text="Action" AutoPostBack="false">
<AjaxEvents>
<Click OnEvent="btnCadastrarModificar_Click" Success="testeRepostaSim" Failure="testeRepostaNao"></Click>
</AjaxEvents>
</ext:Button>


</Content>
</ext:Window>


</form>
</body>
</html>

geoffrey.mcgill
Sep 23, 2008, 12:24 PM
Hi Petherson,

The problem is that you are overwritting the Response stream. You clear everything and then send back a custom response. The AjaxEvent initiating the original request never gets back the response it was expecting.

I simplified your code sample into the following example.

Example


<%@ Page Language="C#" %>


<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>


<!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 Button1_Click(object sender, AjaxEventArgs e)
{
e.Success = this.Checkbox1.Checked;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Ajax Event Success and Failure</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />

<ext:Checkbox ID="Checkbox1" runat="server" />

<ext:Button ID="Button1" runat="server" Text="Submit">
<AjaxEvents>
<Click
OnEvent="Button1_Click"
Success="alert('SUCCESS');"
Failure="alert('FAILURE');"
/>
</AjaxEvents>
</ext:Button>
</form>
</body>
</html>
You can trigger the "Failure" by setting the e.Success property to "false" or throwing an Exception.

Hope this helps.

geoffrey.mcgill
Sep 23, 2008, 12:25 PM
I forgot to mention the example I posted above is using the v0.6 code base.

petherson
Sep 23, 2008, 12:56 PM
I don't understand, I'm using the v0.6 code base too, but I don't have Sucess on the class AjaxEventArgs.
Thank you for your help.

geoffrey.mcgill
Sep 23, 2008, 1:31 PM
The .Success property was added to the AjaxEventArgs only recently. The property/feature will be available with the public release of v0.6.