2012-02-21 48 views

回答

1

您可以在页面上准备好JavaScript函数,或者您可以稍后在登录失败时添加它们。因此,首先捕捉登录失败...

登录模块上你身后乙醚打开JavaScript代码添加事件

<asp:Login OnLoginError="OnLoginError" ... > 

,醚您注册一个新的。

protected void OnLoginError(object sender, EventArgs e) 
{ 
    // this 
    txtMsg.Visible = true; 

    // OR this 
    Page.ClientScript.RegisterStartupScript(
       page.GetType(), "MsgFail", "alert('Login fail');", true); 
} 

假设你有一个这样的javasscript用于第一种情况。

<asp:literal run="server" id="txtMsg" EnableViewState="false" visible="false"> 
<script> 
    alert("login fails"); 
</script> 
</asp:literal> 
+0

JS的功能我想调用函数是周期性的(){ $( '#摇床')效果( '摇',{倍:10},100)。 } – 2012-02-21 22:27:34

+0

@ClemenGronver只是把它放在警报的位置。 – Aristos 2012-02-21 22:53:43

1

您可以在代码隐藏中使用RegisterStartupScript

protected void OnLoginError(object sender, EventArgs e) 
{ 
    Page.ClientScript.RegisterStartupScript(
         GetType(), "SomeName", "SomeFunction();", true); 
} 

其中SomeFunction()是您要调用的JavaScript函数。