[ADDED] [V0.6] ComboBox and RequiredFieldValidator

  1. #1

    [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Hello,

    Can we get the ComboBox to work with the RequiredFieldValidator?

    Would work great for a few scenarios in our product.

    Sincerely,
    Timothy
  2. #2

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Hi Timothy,

    I added functionality to allow the <asp:RequiredFieldValidator> to work (client + server side) the new <ext:ComboBox>.

    The following code sample demonstrates a simple <ext:ComboBox> with <asp:RequiredFieldValidator>.

    Example

    <ext:ComboBox 
        ID="ComboBox1" 
        runat="server">
        <Items>
            <ext:ListItem Text="Item0" />
            <ext:ListItem Text="Item1" />
            <ext:ListItem Text="Item2" />
            <ext:ListItem Text="Item3" />
            <ext:ListItem Text="Item4" />
        </Items>
    </ext:ComboBox>
    
    <asp:RequiredFieldValidator 
        ID="RequiredFieldValidator1" 
        runat="server" 
        ControlToValidate="ComboBox1" 
        Display="Dynamic">!</asp:RequiredFieldValidator>
    There is one problem that quickly becomes apparent with the above sample... the <ext:ComboBox> is treated as a block level element, so the RequiredFieldValidator error message is forced down into the next line if invalid.

    I played around with the <ext:ComboBox> for a while and could not come up with a clean fix, other than adding the <ext:ComboBox> and <asp:RequiredFieldValidator> to separate cells (<td>) of an inline <table>. The following sample demonstrates.

    Example

        Choose Item: 
        <table style="display:inline;">
            <tr>
                <td>
                    <ext:ComboBox 
                        ID="ComboBox1" 
                        runat="server">
                        <Items>
                            <ext:ListItem Text="Item1" />
                            <ext:ListItem Text="Item2" />
                            <ext:ListItem Text="Item3" />
                        </Items>
                    </ext:ComboBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator 
                        ID="RequiredFieldValidator1" 
                        runat="server" 
                        ControlToValidate="ComboBox1" 
                        Display="Dynamic">!</asp:RequiredFieldValidator>
                </td>
            </tr>
        </table>
    
    
    
    <asp:Button ID="Button1" runat="server" Text="Submit" &#111;nclick="Button1_Click" />
    Clearly a pretty gross hack, but it works and might be acceptable until a cleaner css revision can be found.

    Hope this helps.
    Geoffrey McGill
    Founder
  3. #3

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Thanks Geoffrey,

    Server-side works great, client-side still appears to do a post back when you provide ValidationGroup properties?

    <%@ Page Language="C#" %>
    <%@ 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">
    <script runat="server">
        protected void Button1_Click(object sender, EventArgs e)
        {
    
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager runat="server" EnablePartialRendering="True" />
            <ext:ScriptManager runat="server" ScriptMode="Debug" />
            
                Choose Item: 
                <table style="display:inline;">
                    <tr>
                        <td>
                            <ext:ComboBox 
                                ID="ComboBox1" 
                                runat="server">
                                <Items>
                                    <ext:ListItem Text="Item1" />
                                    <ext:ListItem Text="Item2" />
                                    <ext:ListItem Text="Item3" />
                                </Items>
                            </ext:ComboBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator 
                                ID="RequiredFieldValidator1" 
                                runat="server" 
                                ControlToValidate="ComboBox1" 
                                ValidationGroup="ValidationTest"
                                Display="Dynamic">!</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </table>
            
    
    
            <asp:Button ID="Button1" runat="server" CausesValidation="True" ValidationGroup="ValidationTest" Text="Submit" &#111;nclick="Button1_Click" />
    
        </form>
    </body>
    </html>
    Postback happens in FF3.0 when ValidationGroup is present on the Button and RequiredFieldValidator. Works without ValidationGroup on both.

    Cheers,
    Timothy
  4. #4

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Would also like to point out, ValidationGroup works beautifully on Coolite TextField and TextArea, might help! ;)

    Cheers,
    Timothy
  5. #5

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Oops Geoffrey, once more:

    <%@ Page Language="C#" %>
    <%@ 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">
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ComboBox1.SelectedItem.Value = "1";
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
            <ext:ScriptManager ID="ScriptManager2" runat="server" ScriptMode="Debug" />
            
                Choose Item: 
                <table style="display:inline;">
                    <tr>
                        <td>
                            <ext:ComboBox 
                                ID="ComboBox1" 
                                runat="server">
                                <Items>
                                    <ext:ListItem Text="Item1" Value="1" />
                                    <ext:ListItem Text="Item2" Value="2" />
                                    <ext:ListItem Text="Item3" Value="3" />
                                </Items>
                            </ext:ComboBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator 
                                ID="RequiredFieldValidator1" 
                                runat="server" 
                                ControlToValidate="ComboBox1" 
                                Display="Dynamic">!</asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </table>
            
    
    
            <asp:Button ID="Button1" runat="server" Text="Submit" &#111;nclick="Button1_Click" />
    
        </form>
    </body>
    </html>
    Perhaps I'm setting the value wrong; but when I use ComboBox1.SelectedItem.Value = "1"; and try to submit, the validation fires. When I drop down the list and select Item1 from the list validation accepts.

    Cheers,
    Timothy
  6. #6

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Can someone help me out with the above 2 issues?

    1. Client-side validation is not running on ComboBox
    2. Setting the value programmatically and trying to submit causes a validation error

    Cheers,
    Timothy
  7. #7

    RE: [ADDED] [V0.6] ComboBox and RequiredFieldValidator

    Geoffrey McGill
    Founder

Similar Threads

  1. [CLOSED] ComboBox RequiredFieldValidator within DetailsView
    By ljcorreia in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 06, 2009, 12:25 PM
  2. [CLOSED] ComboBox RequiredFieldValidator
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: May 08, 2009, 4:11 PM
  3. Replies: 3
    Last Post: Sep 07, 2008, 2:04 PM

Posting Permissions