你的位置:首页 > ASP.net教程

[ASP.net教程]Ext.Net TextField Enter事件


(1)DirectEvents触发后台

<ext:TextField ID="txt_Upc" runat="server" Width="150">
<DirectEvents>
<KeyPress OnEvent="txtUpc_KeyPress">
<ExtraParams>
<ext:Parameter Name="keynum" Value="e.getKey()" Mode="Raw" />
</ExtraParams>
</KeyPress>
</DirectEvents>
</ext:TextField>

CS后台:

protected void txtUpc_KeyPress(object sender, DirectEventArgs e)
{
string key = e.ExtraParams["keynum"].ToString();
if (key == "13")
{

//do

}
}

(2)Listeners触发前台 

<ext:TextField ID="txt_Upc" runat="server" Width="150">
<Listeners>
<KeyPress Handler="if (e.getKey()==Ext.EventObject.ENTER){Ext.net.DirectMethods.TextKeyPress();e.stopEvent();}" />
<SpecialKey Handler="txtUpcEnter(e.getKey(),#{txt_Upc}.getValue());" />
</Listeners>
</ext:TextField>

JS:

function txtUpcEnter(keynum, value) {
if (keynum== "13") {
}
}

(3)DirectMethods-触发后台

(个人心得,我在扫描枪扫描控件自动Enter时DirectEvents方法不可用,Listeners触发前台方法可用)

<ext:TextField ID="txt_Upc" runat="server" Width="150">
<Listeners>
<KeyPress Handler="if (e.getKey()==Ext.EventObject.ENTER){Ext.net.DirectMethods.TextKeyPress();e.stopEvent();}" />
<SpecialKey Handler="Ext.net.DirectMethods.txtUpcEnter(e.getKey(),#{txt_Upc}.getValue());" />
</Listeners>
</ext:TextField>

CS后台:

[DirectMethod]
public void txtUpcEnter(string key, string value)
{
//
}