使用客户端脚本完成页面回传,执行服务器事件的同时,按钮呈灰色不可用状态

页面部分代码:

<html>
<head runat="server">
<script language="javascript">
function EventGet(obj)
{
    obj.disabled
="disabled";
    
    __doPostBack(obj.id, 
"");
    
return false;
}
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<asp:Button ID="btn_submit" runat="server" OnClick="btn_submit_Click" OnClientClick="return EventGet(this);" Text="Submit" />
    
</form>
</body>
</html>

服务器端代码:
public partial class test : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        ClientScript.GetPostBackEventReference(btn_submit, 
"");
    }

    
protected void btn_submit_Click(object sender, EventArgs e)
    {
        
int i = System.Environment.TickCount / 1000;
        
while (System.Environment.TickCount / 1000 - i < 3)
        {

        }
        btn_submit.Text 
= i.ToString();
    }
}

其中while部分仅为演示按钮变灰的状态。

最终效果。
单击按钮后页面进行服务器端的代码处理,同时整个过程按钮程灰色不可用状态。
待服务器脚本执行完成后,按钮重新可用。

posted on 2010-01-27 09:31  tongdengquan  阅读(136)  评论(0编辑  收藏  举报