(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)
{
//
}