PDA

View Full Version : [CLOSED] how to call btn's click event on server by press "enter" key



hdsoso
May 03, 2013, 12:00 PM
<script>
Ext.getDoc().on('keydown', function (e) {
if (e.getKey() == e.ENTER) {
App.dircect.verycode(); //here I want to call btnLogin's click , how to do thanks.
}
});
</script>

<ext:Button ID="btnLogin" runat="server" Text="登陆" Icon="Accept">
<DirectEvents>
<Click OnEvent="btnLogin_Click">
<EventMask ShowMask="true" Msg="正在验证..." MinDelay="500" />
</Click>
</DirectEvents>
</ext:Button>


[DirectMethod]
protected void verycode()
{
string u = this.txtUsername.Text;
string p = this.txtPassword.Text;
if (u == "admin" && p == "XXX")
{
Session["user"] = "admin";
Response.Redirect("~/index.aspx");
}
else
{
X.MessageBox.Alert("提示", "登陆失败").Show();
}
}
protected void btnLogin_Click(object sender, DirectEventArgs e)
{
verycode();
}


why js show error:
can not call method 'verycode' of underfinde


thanks.

Daniil
May 03, 2013, 12:23 PM
Hi @hdsoso,

Welcome to the Ext.NET forums!

You can use the following.

App.btnLogin.fireEvent("click", btnLogin);

Another approach is using a DirectMethod. With this approach you should replace the DirectEvent with a combination of the Button's Click Listener and a DirectMethod call. Then you will be able to call that DirectMethod from anywhere.

hdsoso
May 05, 2013, 4:52 AM
thanks.you can close the post.