问题描述
我正在将Visual Studio和C#用于Web项目.我使用Visual Studio中的内置功能,Required Field Validator等对许多文本框进行了验证.页面加载后,我的网页上还有一个Submit和Previous按钮 如果我按上一个按钮,除非每个文本框中都没有输入,否则它将不会返回.我想知道如何解决此问题?,我猜我应该在提交"按钮上单击验证".这是我的代码片段以及正在使用的验证, 预先感谢您的帮助.
I'm using Visual studio and C# for a web project. I have a number of Textboxes that I have validated using the built in functions in Visual Studio, the Required Field Validator etc. I also have a Submit and previous button on my webpage, once the page loads if I press the previous button it will not go back unless there is input in each of the textboxes. Im wondering how can I fix this?, I'm guessing I should have the Validation on the Submit button Click. Heres a snippet of my code and the validation I'm using, thanks in advance for any help.
<asp:Table ID="TableDB" runat="server" CssClass="TableDB">
<asp:TableHeaderRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Label ID="Label1" runat="server" CssClass="LabelOpeningThankyou" Text="<b>Database Connection Details</b>"></asp:Label>
</asp:TableCell>
</asp:TableHeaderRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right" Width="150px">Server Name:</asp:TableCell>
<asp:TableCell HorizontalAlign="Left" Width="150px"><asp:TextBox ID="txtServerName" runat="server" CssClass="input_text_singleline1"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter a Server Name" Text="*" ControlToValidate="txtServerName"></asp:RequiredFieldValidator></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Database Name:</asp:TableCell>
<asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="txtDBName" runat="server" CssClass="input_text_singleline1"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please enter Database Name" ControlToValidate="txtDBName" Text="*"></asp:RequiredFieldValidator></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Username:</asp:TableCell>
<asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="txtUsername" runat="server" CssClass="input_text_singleline1"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" Text="*"></asp:RequiredFieldValidator></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right">Password:</asp:TableCell>
<asp:TableCell HorizontalAlign="Left"><asp:TextBox ID="txtPassword" runat="server" CssClass="input_text_singleline1"></asp:TextBox></asp:TableCell>
<asp:TableCell><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Please enter Password" Text="*" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell></asp:TableCell>
<asp:TableCell HorizontalAlign="Right">
<asp:LinkButton ID="btnTestConnection" runat="server" onclick="btnTestConnection_Click"><span>Test Connection</span></asp:LinkButton>
<asp:Label ID="lblTestConnection" runat="server" Text=""></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Right"><asp:LinkButton ID="btnPrevious" runat="server" CssClass="button1floatright" onclick="btnPrevious_Click"><span>Previous</span></asp:LinkButton></asp:TableCell>
<asp:TableCell HorizontalAlign="Left"><asp:LinkButton ID="btnNext2" runat="server" CssClass="button1" onclick="btnNext2_Click"><span>Next</span></asp:LinkButton></asp:TableCell>
</asp:TableRow>
</asp:Table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
推荐答案
var myValidator = document.getElementById('ValidationSummary1');
ValidatorEnable(myValidator , false);
这篇关于验证按钮点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!