C# 在asp.Net中输入textchanged事件的文本框时如何避免按钮单击事件
我有一个以月份为值的文本框,当它被更改时,将触发包含vaildtextbasemonth()方法的text_changed事件C# 在asp.Net中输入textchanged事件的文本框时如何避免按钮单击事件,c#,asp.net,methods,C#,Asp.net,Methods,我有一个以月份为值的文本框,当它被更改时,将触发包含vaildtextbasemonth()方法的text_changed事件 private void validTextBaseMonth() { this_month=DateTime.Now.month; 当前年=DateTime.Now.year; 本年=转换为32(TxtBase.Text); 当前月份=DateTime.Now.month; 如果(swyearerror!=0) { swyearerror=0; TxtBase.Foc
private void validTextBaseMonth()
{
this_month=DateTime.Now.month;
当前年=DateTime.Now.year;
本年=转换为32(TxtBase.Text);
当前月份=DateTime.Now.month;
如果(swyearerror!=0)
{
swyearerror=0;
TxtBase.Focus();
}
else if(Information.IsNumeric(TxtBase1.Text))
{
基本月=转换为32(TxtBase1.Text);
如果(基准月>本月&当前年==本年)
{
string message=“基准月可能不在将来”;
System.Text.StringBuilder sb=新的System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());
TxtBase1.Focus();
}
其他的
{
如果(基准月<1 |基准月>12)
{
string message=“月份必须是数字”;
System.Text.StringBuilder sb=新的System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());
TxtBase1.Focus();
}
其他的
{
如果(基准月!=当前月)
{
当前月份=基准月份;
计算旋转();
计算之前的最佳值();
}
//txtBestBefore.SetFocus
}
}
}
其他的
{
string message=“月份必须是数字”;
System.Text.StringBuilder sb=新的System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());
TxtBase1.Focus();
}
}
这是打印按钮的.aspx
<asp:Button ID="Print" runat="server"
OnClick="Print_Click1" Text="Print" />
这是打印按钮的代码,这很烦人,因为根据我的程序流程,用户更改月份,然后填充新的轮换代码和best before date,然后用户输入要打印的数量,然后单击“打印”按钮,但在这里,由于用户更改文本时会自动触发打印事件,因此会抛出一个错误,说明数量为空在打印单击事件中选中
protected void Print_Click1(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(TxtItem.Text)
&& String.IsNullOrEmpty(TxtQty.Text))
{
string message = "Please Enter an Item
and Qty Before Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString());
}
else if (String.IsNullOrEmpty(TxtQty.Text))
{
string message = "Please Enter an Qty Before
Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString());
}
else if (String.IsNullOrEmpty(TxtItem.Text))
{
string message = "Please Enter an Item
Before Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString()); }
else
{
Printlabels();
}
}
protected void Print\u Click1(对象发送者,事件参数e)
{
if(String.IsNullOrEmpty(TxtItem.Text)
&&String.IsNullOrEmpty(TxtQty.Text))
{
string message=“请输入一个项目
点击打印按钮前的数量”;
System.Text.StringBuilder sb=新建
System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());
}
else if(String.IsNullOrEmpty(TxtQty.Text))
{
string message=“请在输入数量之前
单击“打印”按钮”;
System.Text.StringBuilder sb=新建
System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());
}
else if(String.IsNullOrEmpty(TxtItem.Text))
{
string message=“请输入一个项目
单击“打印”按钮之前”;
System.Text.StringBuilder sb=新建
System.Text.StringBuilder();
某人加上(“”);
sb.Append(“window.onload=function(){”);
某人加上(“警告(”);
某人附加(信息);
某人加上(“)};”;
某人加上(“”);
ClientScript.RegisterClientScriptBlock
(this.GetType(),“alert”,sb.ToString());}
其他的
{
打印标签();
}
}
所以在这个事件之后,print button click事件被自动触发,我检查了代码,我没有看到对click按钮的调用,我不知道为什么它将另一个方法作为有效的基本项方法的一部分
非常感谢您的帮助尝试查看Print\u Click1方法是否未定义为HTML中另一个事件的句柄。据我所知,如何才能做到这一点,它未定义为任何其他事件的句柄
protected void Print_Click1(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(TxtItem.Text)
&& String.IsNullOrEmpty(TxtQty.Text))
{
string message = "Please Enter an Item
and Qty Before Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString());
}
else if (String.IsNullOrEmpty(TxtQty.Text))
{
string message = "Please Enter an Qty Before
Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString());
}
else if (String.IsNullOrEmpty(TxtItem.Text))
{
string message = "Please Enter an Item
Before Clicking the Print Button";
System.Text.StringBuilder sb = new
System.Text.StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload=function(){");
sb.Append("alert('");
sb.Append(message);
sb.Append("')};");
sb.Append("</script>");
ClientScript.RegisterClientScriptBlock
(this.GetType(), "alert", sb.ToString()); }
else
{
Printlabels();
}
}