[CLOSED] Checkbox value update issue.

  1. #1

    [CLOSED] Checkbox value update issue.

    I have a checkbox that I need to change the value after selected value on combo.

    But something is wrong. Because I'm not able to change this, whatever I do, the value still the same.

    Steps to reproduce:

    1. Change the combobox value to "two";
    2. Change the checkbox value to "checked";
    3. Now change the combobox value.

    Doesn't matter which value I select on combo, the checked value on checkbox remains.

    Support Code:

    Code design:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    
        <script language="javascript" type="text/javascript">
            var ChangeValue = function(value)
            {
                myChk.checked = false;
                myChk.setDisabled(true);
                if(value == "2")
                    myChk.setDisabled(false);
            }
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager runat="server">
        </ext:ResourceManager>
        <ext:Checkbox runat="server" ID="myChk" Disabled="true">
        </ext:Checkbox>
        <ext:ComboBox runat="server" ID="myCbo">
            <Listeners>
                <Select Handler="ChangeValue(myCbo.getSelectedItem().value);" />
            </Listeners>
        </ext:ComboBox>
        </form>
    </body>
    </html>
    Code behind:

    protected void Page_Load(object sender, EventArgs e)
            {
                myCbo.Items.Add(new Ext.Net.ListItem("one", "1"));
                myCbo.Items.Add(new Ext.Net.ListItem("two", "2"));
                myCbo.Items.Add(new Ext.Net.ListItem("three", "3"));
    
            }
    last svn update: 08/26/2011

    tks :)

    []'s
    Last edited by Daniil; Sep 20, 2011 at 11:17 AM. Reason: [CLOSED]
  2. #2
    Hi Marcelo,

    Please use .setValue()
    myChk.setValue(false);
    instead of
    myChk.checked = false;
    .checked is just a config option and doesn't make sense after rendering.
  3. #3
    Ok!.
    setValue() works fine when I use Ext.Net.Checkbox.

    But I need to override setValue() (javacript method), because I'm extend Ext.Net.Checkbox on my own checkbox.

    I have to do that because my customers likes field label on right side of checkbox
    I try to do this:
    <ext:Checkbox runat="server" ID="myChk" Disabled="true" FieldLabel="Ext.Net Checkbox"
            LabelAlign="Right">
        </ext:Checkbox>
    but, the field label doesn't appear on right side, so I create my own checkbox using a CompositeField.

    here is the code for my own checkbox
    namespace ERP.Net
    {
        public class CheckBox : Ext.Net.CompositeField, System.Web.UI.ICheckBoxControl
        {
            #region Locais
            public Ext.Net.Label MainLabel
            {
                get { return Items[1] as Ext.Net.Label; }
            }
            #endregion
    
            #region Construtores
            public CheckBox()
                : base()
            {
                Initialize();
            }
    
            private void Initialize()
            {
                LabelAlign = Ext.Net.LabelAlign.Right;
                //cria o checkbox
                Ext.Net.Checkbox c = new Ext.Net.Checkbox();
                Items.Add(c);
    
                Ext.Net.Label l = new Ext.Net.Label();
                Items.Add(l);
    
                base.FieldLabel = "";
            }
            #endregion
    
            #region Overrides
            public new string FieldLabel
            {
                get
                {
                    return MainLabel.Text + ":";
                }
                set
                {
                    MainLabel.Text = value;
                }
            }
    
            #endregion
    
            #region ICheckBoxControl Members
    
            public bool Checked
            {
                get
                {
                    Ext.Net.Checkbox c = Items[0] as Ext.Net.Checkbox;
                    return c.Checked;
                }
                set
                {
                    Ext.Net.Checkbox c = Items[0] as Ext.Net.Checkbox;
                    c.Checked = value;
                    if (!string.IsNullOrEmpty(c.ClientID))
                        c.AddScript(c.ClientID + ".setValue(" + (value ? 1 : 0).ToString() + ");");
                    if (CheckedChanged != null)
                        CheckedChanged(c, new EventArgs());
                }
            }
    
            public event EventHandler CheckedChanged;
    
            #endregion
        }
    }
    This works fine, but now I have this issue.

    there is a way to override setValue client side?

    Sorry, If I didn't make myself clear.

    []'s
  4. #4
    May be you need to use BoxLabel property if right alignment is required
  5. #5
    Thanks.
    Works fine.

    Here is my solution for my own checkbox.

    namespace ERP.Net
    {
        public class CheckBox : Ext.Net.Checkbox
        {
            #region Construtores
            public CheckBox()
                : base()
            {
                Initialize();
            }
    
            private void Initialize()
            {
                BoxLabelCls = "x-form-field";
            }
            #endregion
    
            #region Overrides
            public new string FieldLabel
            {
                get { return BoxLabel; }
                set { BoxLabel = value; }
            }
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
    
                if (LabelAlign != LabelAlign.Right)
                {
                    base.FieldLabel = FieldLabel;
                    BoxLabel = "";
                }
            }
            #endregion
        }
    }
    But. Just for my knowledgement, there is some tutorial that teach me how can override some methods on javascript?
    Or some place that I could get to study to get more knowledge on ext.net development, and do my codes better and professional?


    []'s
  6. #6
    I don't know about such tutorial.

    To override the setValue() method you can use CustomConfig or extend JavaScript class with overriding.
  7. #7
    Hi Daniil,

    With your tip I did a search on fórum and I found this topic

    http://forums.ext.net/showthread.php...om-numberField

    It's a good start for me...

    Thanks :)

    PS: Please, mark as solved.
  8. #8
    Yes, there is a good example what you need to do.

Similar Threads

  1. [CLOSED] Checkbox issue
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 14, 2011, 2:38 PM
  2. Runtime Checkbox value update issue.
    By ajviradia in forum 1.x Help
    Replies: 1
    Last Post: Apr 08, 2011, 5:23 PM
  3. CheckBox Update Problem in Gridview.
    By Ganesh3.shirsath in forum 1.x Help
    Replies: 0
    Last Post: Jan 07, 2011, 9:03 AM
  4. [CLOSED] Problem with checkbox due to SVN update
    By CSG in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Nov 25, 2009, 8:09 AM
  5. [CLOSED] CheckBox Issue
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Sep 13, 2009, 1:38 PM

Tags for this Thread

Posting Permissions