AjaxEvents From CodeBehind

  1. #1

    AjaxEvents From CodeBehind

    Hi Everybody,
    I'm having some troubles building my application interface completely from codebehind.
    First, I post the incriminated code:

          
          (some code here...)
          ....
          public Coolite.Ext.Web.Button GetLoginButton()
           {
                    /*--------------------------------------
                     * Button Login Creation
                     * -------------------------------------*/
                    if (this.btnLogin == null)         
                    {
                         Coolite.Ext.Web.Button ButtonLogin = new Coolite.Ext.Web.Button();
                         ButtonLogin.ID = "ButtonLogin";
                         ButtonLogin.Text = "Login";
                         ButtonLogin.Icon = Icon.Accept;
                         ButtonLogin.AjaxEvents.Click.Event += new ComponentAjaxEvent.AjaxEventHandler    (ButtonLogin_Click); 
    
    
                        ButtonLogin.AjaxEvents.Click.EventMask.ShowMask = true;
                        ButtonLogin.AjaxEvents.Click.EventMask.Msg = "Wait...";
                        ButtonLogin.AjaxEvents.Click.EventMask.MinDelay = 1000;
                        this.btnLogin = ButtonLogin ;
                }
                return(this.btnLogin);
            }
    
           protected void ButtonLogin_Click(object sender, AjaxEventArgs e)
            {
                // Do Something....       
           }
            
    
           protected void Page_Load(object sender, EventArgs e)
            {
                // Add The Login Window that it contains the Login Button
                this.formMain.Controls.Add(GetLoginWindow());
            }
    
           ....
           (some code here...)
    Here's the problem:
    The Login Window display correctly inside the page with the Login button inside it.
    Pressing the button the Event Mask display but after 1 second a runtime error appears inside an ext error window saying:


    Server Error in '/' Application.
    System.Web.HttpException: The control with ID 'ButtonLogin' not found

    Does somebody know the possible cause of this error?
    Help Please

    Thanks....

    Andrea Cammarata WebSite
  2. #2

    RE: AjaxEvents From CodeBehind

    Hi,

    Can you post full code of example? It seems ???? the button will not be recreated on the ajax event.

    Vladimir Shcheglov
    Sr. Developer
  3. #3

    RE: AjaxEvents From CodeBehind

    Hi Andrea,

    If you are dynamically creating controls, please ensure you recreate the control on each request. You GetLoginButton() Method would need to be called on each request. Posting a code sample demonstrating where that method is called should help us diagnose the problem. 


    Geoffrey McGill
    Founder & CEO
  4. #4

    RE: AjaxEvents From CodeBehind

    Thank you everibody to reply so fast to my problem.
    Thank to you i solve the problem:
    Like geoffrey.mcgill says i need to ricreate the entire interface on each request.
    In fact my Default.aspx PageLoad was:

           using BackEnd;
    
           protected void Page_Load(object sender, EventArgs e)
            {
                if(!Page.IsPostBack)
                {
                    // Create the entire applocation interface
                    Interface Software = new Interface();
                    this.formMain.Controls.Add(GetMainInterface());
                }
           }
    so i had to change the code like below to solve the problem.

           using BackEnd;
    
           protected void Page_Load(object sender, EventArgs e)
            {
                // Create the entire application interface
                Interface Software = new Interface();
                this.formMain.Controls.Add(GetMainInterface());
           }
    But now i have a question:
    If the ButtonLogin_Click is wrapped inside an AjaxEvent, why clicking on it the entire page will be loaded?This is not Ajax...

    NOTE: The function GetMainInterface() is located inside a Interface.cs (namespace BackEnd) in my App_Code directory.

    Thank you all for support,

    Andrea Cammarata WebSite
  5. #5

    RE: AjaxEvents From CodeBehind

    But now i have a question:
    If the ButtonLogin_Click is wrapped inside an AjaxEvent, why clicking on it the entire page will be loaded?This is not Ajax...
    I am not sure what you mean? Can you explain further?


    Geoffrey McGill
    Founder & CEO
  6. #6

    RE: AjaxEvents From CodeBehind

    Sure,
    if you take a look at the code below

       ButtonLogin.AjaxEvents.Click.Event += new ComponentAjaxEvent.AjaxEventHandler(ButtonLogin_Click);
    
       protected void ButtonLogin_Click(object sender, AjaxEventArgs e)
       {
           // Do Something....       
       }
    The ButtonLogin Click Event is defined like an ajaxevent, but if i click on it, at the debug time, the page will reload completely and after that Page_Load complete, the function ButtonLogin_Click() fires.
    If is an ajax event, why all the page need to be rewritted?

    Thanks...

  7. #7

    RE: AjaxEvents From CodeBehind

    I copy/paste your code into a new .aspx Page and the AjaxEvent fires perfectly.

    Can you paste a simplified .aspx code sample demonstrating how to reproduce this issue? Unless you have set the .AutoPostBack property on the button to "true" it's impossible for the <ext:Button> to trigger a postback.


    Geoffrey McGill
    Founder & CEO

Similar Threads

  1. AjaxEvents
    By qch2006qch in forum 1.x Help
    Replies: 1
    Last Post: Apr 11, 2012, 1:16 PM
  2. Ext.Msg before AjaxEvents
    By fquintero in forum 1.x Help
    Replies: 2
    Last Post: Aug 10, 2009, 2:44 PM
  3. Conditional AjaxEvents
    By grmontero in forum 1.x Help
    Replies: 1
    Last Post: May 29, 2009, 11:40 AM
  4. [FIXED] [V0.7] AjaxEvents bug
    By amin_itm in forum Bugs
    Replies: 5
    Last Post: Dec 01, 2008, 3:45 AM
  5. What is this problem with AJAXEVENTS
    By egof in forum 1.x Help
    Replies: 2
    Last Post: Oct 14, 2008, 8:04 PM

Posting Permissions