页面回发中触发ASP Textbox验证 [英] ASP Textbox validation fire in the page postback

查看:50
本文介绍了页面回发中触发ASP Textbox验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Obout日历控件(适用于ASP.NET 3.5的obout套件)来选择asp文本框的日期.表单具有一个按钮,单击该按钮时,表单数据将写入sql表并清除表单控件. asp必填字段验证器用于文本框.

错误是,在回发中,文本框的验证正在触发.
返回到单击按钮的页面时如何停止触发此验证.
代码如下.

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.

<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" />



button_click事件



the button_click event

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

推荐答案



您需要为给定的代码创建validationGroup.

像这样更新代码,
Hi,

You need to create validationGroup for given code.

Update your code like,
<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" />



希望这对您有帮助,

谢谢
-Amit Gajjar



Hope this helps you,

Thanks
-Amit Gajjar


通过使文本框属性为ReadOnly ="False",可以解决此问题.
By making the text box property ReadOnly="False" this problem can be solved.


这篇关于页面回发中触发ASP Textbox验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆