Checkbox changed handler in code-behind

  1. #1

    Checkbox changed handler in code-behind

    Hi...this seems like it ought to be simple to do (I can do it pretty easily in .net, anyway), but I'm stuck.

    I have a checkbox and a textarea. The checked/unchecked state of the checkbox should control the enabled/disabled state of the textarea (and clear the textarea's content when unchecked).

    I'm trying to figure out the proper way to tell the checkbox to call a function in code-behind to accomplish this. Something like:

    <ext:Checkbox runat="server" ID="Checkbox1" BoxLabel="Toggle the textarea">
            <Listener>
                    <Change Handler="toggleText" />
            </Listener>
    </ext:Checkbox>
    <ext:TextArea ID="txtTest" runat="server" FieldLabel="Text Area" Enabled="false"></ext:TextArea>
    and in the code-behind:

    protected void toggleText()
    {
        if (!Checkbox1.Checked)
        {
            txtTest.Enabled = false;
            txtTest.Clear();
        }
        else
        {
            txtTest.Enabled = true;
        }
    }
    ...formgroup seems to do something similar (hides/shows a portion of the page, rather than enable/disable), but both the checkbox and textarea will be data-bound.

    How do I call a function in code-behind from the checkbox changed event? Do I need to use an ajaxevent and add some more plumbing to the page?
  2. #2

    RE: Checkbox changed handler in code-behind

    Hi,

    Listener is client side events (call js code)
    You need use AjaxEvent
    <Click OnEvent="ToggleText" ...
    protected void ToggleText(object sender, AjaxEventArgs e)
  3. #3

    RE: Checkbox changed handler in code-behind

    I did try that before (and again, just now). Breakpoint (at "if (!Checkbox1.Checked)") is not getting hit in the code-behind. Here's the code I'm testing with:

    Toggle.aspx
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Toggle.aspx.cs" Inherits="Toggle" %>
    
    <%@ 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">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
            <ext:Desktop ID="Panel1" runat="server" AutoHeight="True" Header="True" Height="600px">
                <Body>
                    <ext:Checkbox runat="server" ID="Checkbox1" BoxLabel="Toggle the textarea">
                        <AjaxEvents>
                            <Change OnEvent="toggleText" />
                        </AjaxEvents>
                    </ext:Checkbox>
                    <ext:TextArea ID="txtTest" runat="server" FieldLabel="Text Area" Enabled="false"></ext:TextArea>
                </Body>
            </ext:Desktop>
        
    
        </form>
    </body>
    </html>
    Toggle.aspx.cs
    using Coolite.Ext.Web;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Toggle : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
    
        protected void toggleText(object sender, AjaxEventArgs e)
        {
            if (!Checkbox1.Checked)
            {
                txtTest.Enabled = false;
                txtTest.Clear();
            }
            else
            {
                txtTest.Enabled = true;
            }
        }
    }
  4. #4

    RE: Checkbox changed handler in code-behind

    Hi,

    You need use Check event instead Change
  5. #5

    RE: Checkbox changed handler in code-behind

    ...okay. So, check fires on Check and Uncheck, and Change fires when? (Are these extjs questions I'm asking?)
  6. #6

    RE: Checkbox changed handler in code-behind

    Hi,

    Change - Fires just before the field blurs if the field value has changed.
  7. #7

    RE: Checkbox changed handler in code-behind

    That's helpful to know...is there documentation for the Coolite toolkit aside from the examples pages? If not, is it planned, and do you need volunteers to help contribute examples?

Similar Threads

  1. Replies: 4
    Last Post: Jun 28, 2012, 11:32 PM
  2. Replies: 2
    Last Post: Mar 11, 2012, 3:55 AM
  3. [CLOSED] TextField.FieldLabel is not changed in Code Behind
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 24, 2012, 3:28 PM
  4. Gridpanel Listner handling checkbox changed
    By shijith in forum 1.x Help
    Replies: 0
    Last Post: Aug 04, 2010, 6:05 AM
  5. Handler/Fn for column (code behind)
    By roszman in forum 1.x Help
    Replies: 1
    Last Post: Apr 28, 2010, 4:36 AM

Posting Permissions