[CLOSED] Form control values are not updated during DirectEvent

  1. #1

    [CLOSED] Form control values are not updated during DirectEvent

    I am trying to retrieve the value from a drop-down list within a DirectEvent handler. Am I doing something incorrectly, or is this maybe a feature that hasn't been implemented?

    I have legacy code that I need to mix with Coolite controls, so I'm trying to replace UpdatePanels with this mechanism.

    The sample below demonstrates the issue:

    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack || X.IsAjaxRequest)
                {
                    ddlTemplates.DataSource = new object[] {
                        new { Name = "Template A", ID=1 },
                        new { Name = "Template B", ID=2 }
                    };
                    ddlTemplates.DataBind();
                }
            }
    
            protected void btnApplyTemplate_Click(object sender, Ext.Net.DirectEventArgs e)
            {
                string templateID = ddlTemplates.SelectedValue;
    
                X.Msg.Notify("Status", "You selected: " + ddlTemplates.SelectedItem.Text).Show();
    
                lblTemplateName.Text = "I am using template " + templateID;
                lblTemplateName.Update();
            }
        </script>
        
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="extManager" runat="server" IDMode="Static">
                <CustomDirectEvents>
                    <ext:DirectEvent Target="btnApplyTemplate" OnEvent="btnApplyTemplate_Click">
                        <EventMask ShowMask="true" Msg="Working..." />
                    </ext:DirectEvent>
                </CustomDirectEvents>
            </ext:ResourceManager>
        
            <asp:DropDownList ID="ddlTemplates" runat="server" DataTextField="Name" DataValueField="ID" />
            <br />
            <asp:Button runat="server" ID="btnApplyTemplate" Text="Apply" />
            <br /><br />
            <asp:Label ID="lblTemplateName" runat="server" />
        </div>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Jul 26, 2010 at 7:02 AM.
  2. #2
    Hi,

    I think you should be using !X.IsAjaxRequest instead of X.IsAjaxRequest. You were rebinding the form values during each DirectEvent.

    Here's a full sample with the corrected code and a little clean-up.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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)
        {
            if (!IsPostBack || !X.IsAjaxRequest)
            {
                this.DropDownList1.DataSource = new object[] {
                    new { Name = "Template A", ID = 1 },
                    new { Name = "Template B", ID = 2 }
                };
                
                this.DropDownList1.DataBind();
            }
        }
    
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            string templateID = this.DropDownList1.SelectedValue;
    
            X.Msg.Notify("Status", "You selected: " + this.DropDownList1.SelectedItem.Text).Show();
    
            this.Label1.Text = "I am using template " + templateID;
            this.Label1.Update();
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server">
                <CustomDirectEvents>
                    <ext:DirectEvent Target="Button1" OnEvent="Button1_Click">
                        <EventMask ShowMask="true" Msg="Working..." />
                    </ext:DirectEvent>
                </CustomDirectEvents>
            </ext:ResourceManager>
         
            <asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Name" DataValueField="ID" />
            
            <br />
            
            <asp:Button ID="Button1" runat="server" Text="Submit" />
            
            <br />
            <br />
            
            <asp:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Hope this helps.
    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] Is it possible to control child form controls from main form?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Aug 13, 2012, 12:24 PM
  2. [CLOSED] Server side controls values with DirectEvent calls
    By Daniil in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Feb 10, 2012, 11:52 AM
  3. Replies: 2
    Last Post: Jan 16, 2012, 10:34 AM
  4. Replies: 5
    Last Post: Aug 03, 2010, 11:20 AM
  5. [CLOSED] Retrieving form values
    By sz_146 in forum 1.x Help
    Replies: 2
    Last Post: Oct 24, 2008, 5:06 AM

Tags for this Thread

Posting Permissions