在一个表单中有两个文本框和一个按钮,其值为提交。如果任何用户在文本框中输入一些值后单击提交按钮,则按钮的值将更改为成功,即提交按钮变为成功按钮,
但我的问题是,当任何用户单击提交按钮而不在文本框中输入任何值时,它会显示必填字段验证,同时提交按钮变为成功按钮,即使未提交表单。
<form id="form1" runat="server">//code in default.aspx page
<div>
<div>
<br />
<asp:TextBox ID="TextBox1" runat="server" Width="242px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator"
ValidationGroup="s"></asp:RequiredFieldValidator>
<br />
<br />
<asp:TextBox ID="TextBox2" runat="server" Width="242px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="RequiredFieldValidator"
ValidationGroup="s"></asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="btn1" runat="server" Text="MyButton"
OnClientClick="hello();"
onclick="btn1_Click" ValidationGroup="s" />
</div>
</div>
</form>
//code in default.aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn1_Click(object sender, EventArgs e)
{
btn1.Text = "Success";
}
}