How to dislay Validation Message from code behind
<p>I have one textbox..
i want to validate it's value based on dropdownlist value..
So i am displaying message from code behind using <code>RegularExpressionValidator</code>..
But it is not working plz,give me suggestion..                    </p>

<pre><code>&lt;asp:TextBox ID="tbnooflecture" runat="server"  Width="119px" Height="33px"&gt;&lt;/asp:TextBox&gt;

              &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator1"  ForeColor="#6600FF" 
                runat="server"  ValidationGroup="upper" 
                     ControlToValidate="tbnooflecture"&gt;&lt;/asp:RegularExpressionValidator&gt;
 &lt;asp:Button ID="bfillattendence" runat="server" Text="To Fill Attendence Click Here"
                            onclick="FillAttendence_Click" Width="218px"  Height="33px" CausesValidation="true" ValidationGroup="upper"/&gt;
</code></pre>

<p>i am writing below code in Button click event</p>

<pre><code>string  batchname = dpbatchname.SelectedItem.Text.ToString();
        int lengthofbatch=batchname.Length;
        if(lengthofbatch==2)
        {
            RegularExpressionValidator1.ValidationExpression = "[1-9][02468]|[02468]";

        RegularExpressionValidator1.ErrorMessage = "Only Even No. of Attendence is Valid for Lab.";
        }
        else if (lengthofbatch == 1)
        {
            RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
            RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
        }
        else
        {
            RegularExpressionValidator1.ValidationExpression = "[0-9][0-9]|[0-9]";
            RegularExpressionValidator1.ErrorMessage = "Attendence Shold be Like 9,50";
        }
</code></pre>
