[CLOSED] Ajaxevent always call failure

  1. #1

    [CLOSED] Ajaxevent always call failure

    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>

  2. #2

    RE: [CLOSED] Ajaxevent always call failure



    Hi petherson,

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

    RE: [CLOSED] Ajaxevent always call failure

    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>
  4. #4

    RE: [CLOSED] Ajaxevent always call failure



    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
    Founder
  5. #5

    RE: [CLOSED] Ajaxevent always call failure



    I forgot to mention the example I posted above is using the v0.6 code base.
    Geoffrey McGill
    Founder
  6. #6

    RE: [CLOSED] Ajaxevent always call failure

    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.

  7. #7

    RE: [CLOSED] Ajaxevent always call failure



    The .Success property was added to the AjaxEventArgs only recently. The property/feature will be available with the public release of v0.6.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 16
    Last Post: Oct 04, 2011, 5:17 PM
  2. Ajaxevent Request failure
    By lisaloomh in forum 1.x Help
    Replies: 2
    Last Post: Feb 05, 2010, 5:13 AM
  3. Call AjaxEvent from Javascript?
    By lionelhutz in forum 1.x Help
    Replies: 2
    Last Post: Dec 03, 2009, 10:38 PM
  4. [CLOSED] Configure default AjaxEvent failure window
    By jchau in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 15, 2009, 10:55 AM
  5. Replies: 2
    Last Post: Nov 26, 2008, 12:17 PM

Posting Permissions