Click here to Skip to main content
15,883,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Obout calendar control (obout suite for ASP.NET 3.5) to select the date to asp text box. The form has a button and when click the button, form data will write to sql table and will clear the form control. asp required field validator is used for the textbox.

The error is, in the postback, the validation for the text box is firing.
How to stop this validation from firing when coming back to the page on clicking the button.
Code is given below.

XML
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True"></asp:TextBox>

    <obout:Calendar ID="Calendar1"
        runat="server" DatePickerMode="True" TextBoxId="TextBox1">
    </obout:Calendar>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
    <br />
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />


the button_click event

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Calendar1.SelectedDate = new DateTime(0);
        TextBox1.Text = "";
    }
Posted

Hi,

You need to create validationGroup for given code.

Update your code like,
ASP.NET
<asp:textbox id="TextBox1" runat="server" validationgroup="group" readonly="True" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="Button1" runat="server" text="Button" validationgroup="group" onclick="Button1_Click" xmlns:asp="#unknown" />


Hope this helps you,

Thanks
-Amit Gajjar
 
Share this answer
 
By making the text box property ReadOnly="False" this problem can be solved.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900