asp.net 点击按钮提交后使按钮变灰不可用
时间:2022-06-26 10:33:37|栏目:.NET代码|点击: 次
.aspx
<script language="javascript">
function abc()
{
var mybutton=document.getElementById("Submit1");
mybutton.disabled=true; //变灰
__doPostBack("Submit1",""); //执行服务器端Submit1的click事件
}
</script>
<form id="Form1" method="post" runat="server">
...
<INPUT id="Submit1" type="submit" value="开始上传" name="Submit1" runat="server">
....
</form>
.cs
private void Page_Load(object sender, System.EventArgs e)
{
...
this.GetPostBackEventReference(Submit1); //这句很关键,有这句才能让客户端执行服务器端事件。
Submit1.Attributes.Add("onclick","abc();");
....
}
复制代码 代码如下:
<script language="javascript">
function abc()
{
var mybutton=document.getElementById("Submit1");
mybutton.disabled=true; //变灰
__doPostBack("Submit1",""); //执行服务器端Submit1的click事件
}
</script>
<form id="Form1" method="post" runat="server">
...
<INPUT id="Submit1" type="submit" value="开始上传" name="Submit1" runat="server">
....
</form>
.cs
复制代码 代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
...
this.GetPostBackEventReference(Submit1); //这句很关键,有这句才能让客户端执行服务器端事件。
Submit1.Attributes.Add("onclick","abc();");
....
}