radio button always returns false

  1. #1

    radio button always returns false

    This may sounds stupid but if I check if the radio button is checked it always returns false. How do I check which radio button in a group has been selected?


    Front-end Code:
    
    <ext:Radio runat="server" ID="Always2" GroupName="CLOccurance2" FieldLabel="Always" InputValue="Always" AnchorHorizontal="85%" Width="60" />
    <ext:Radio runat="server" ID="Sometimes2" GroupName="CLOccurance2" FieldLabel="Sometimes" InputValue="Sometimes"  AnchorHorizontal="85%" Width="60" />
    Codebehind:
    /** Both of the following returns false **/
            String radioChecked1 = Always2.Checked.ToString();
            String radioChecked2 = Sometimes2.Checked.ToString();
    Thank you.:confused:
  2. #2


    Example

    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            string val1 = this.Radio1.Checked.ToString();
            string val2 = this.Radio2.Checked.ToString();
            
            X.Msg.Notify("Text", string.Format("{0} : {1}", val1, val2)).Show();
        }
    </script>
     
    <!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>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
             
            <ext:Radio
                ID="Radio1" 
                runat="server" 
                Name="Group1"
                FieldLabel="Radio 1" 
                InputValue="one" 
                />
                
            <ext:Radio 
                ID="Radio2" 
                runat="server"
                Name="Group1"
                FieldLabel="Radio 2" 
                InputValue="two"  
                />
            
            <ext:Button runat="server" Text="Submit" OnDirectClick="Button1_Click" />
        </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  3. #3
    Thank you for the reply. Looking at your code I realized that it wasn't working because of the way I was calling the method:

     <ext:Button ID="Button1" runat="server" Text="Save" Icon="Accept">
                        <Listeners>
                            <Click Handler="if (#{FormPanel1}.getForm().isValid()) {Ext.net.DirectMethods.SubmitNewCourse();}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'Please check the fields and try again!', buttons:Ext.Msg.OK});}" />
                        </Listeners>
                    </ext:Button>

     public void SubmitNewCourse()
        {
            String radioChecked1 = Always2.Checked.ToString();
            String radioChecked2 = Sometimes2.Checked.ToString();
    }
    If I use onDirectClick on the button then change the method to have "object sender, DirectEventArgs e" it works fine.

    Can I still have validation like I have it above and make it work?

    The following code doesn't work. Not sure what the correct way of doing it is:

     <ext:Button ID="Button1" runat="server" Text="Save" Icon="Accept">
                        <Listeners>
                            <Click Handler="if (#{FormPanel1}.getForm().isValid()) {Ext.net.DirectMethods.SubmitNewCourse;}else{Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: 'Please check the fields and try again!', buttons:Ext.Msg.OK});}" />
                        </Listeners>
                    </ext:Button>

     public void SubmitNewCourse(object sender, DirectEventArgs e)
        {
            String radioChecked1 = Always2.Checked.ToString();
            String radioChecked2 = Sometimes2.Checked.ToString();
    }
  4. #4

    DirectEvent with Form Validation

    Now that it works, it looks quite simple... and I feel stupid.

    Thank you for the help. You can mark this as solved.
  5. #5
    Thanks for the update. Glad to hear it's working for you now.

    In future forum posts, providing a full .aspx code sample, similar to the sample I posted above, will give us a better idea of your scenario and let us see all the moving parts. Posting snippets of code picked from the page will not get the whole message across.
    Geoffrey McGill
    Founder

Similar Threads

  1. Replies: 2
    Last Post: Apr 09, 2012, 2:13 PM
  2. Radio Button
    By Vaishali in forum 1.x Help
    Replies: 4
    Last Post: Feb 07, 2012, 7:00 AM
  3. radio button always return false
    By hector_toy82 in forum 1.x Help
    Replies: 0
    Last Post: Nov 17, 2010, 7:11 PM
  4. [CLOSED] DateField IsEmpty always returns false
    By brettmas in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 23, 2010, 1:29 AM
  5. Radio button values always shows false
    By vs.mukesh in forum 1.x Help
    Replies: 0
    Last Post: Jul 01, 2010, 3:52 PM

Tags for this Thread

Posting Permissions