PDA

View Full Version : [CLOSED] why keyup event not be triggered?



tobros
Aug 01, 2013, 7:40 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm8" %>
<%@ Register TagPrefix="a" Namespace="System.Data.Entity.Migrations.Model" Assembly="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<script runat="server">


public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public string Cate { get; set; }
}


public List<Company> GetData()
{
return new List<Company>
{
new Company{ID = 1,Name = "comp1",Cate = "餐饮"},
new Company{ID = 2,Name = "comp2",Cate = "电子"},
};
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindData();

}
}
private void BindData()
{
this.store1.DataSource = GetData();
this.store1.DataBind();
}

private static bool b = true;
protected void clickme(object sender, DirectEventArgs e)
{
if (b)
{
this.cc_bz.Hidden = false;
b = false;
}
else
{
this.cc_bz.Hidden = true;
b = true;

}

}
protected void selectme(object sender, DirectEventArgs e)
{
X.Msg.Alert("sss","ddd").Show();
}

</script>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gridpanel1" Height="100">
<TopBar>

<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="show the column">
<DirectEvents>
<Click OnEvent="clickme"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="store1">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Cate"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" DataIndex="ID" Text="ID"></ext:Column>
<ext:Column ID="Column1" runat="server" DataIndex="Name" Text="NAME"></ext:Column>
<ext:Column ID="Column2" runat="server" DataIndex="Cate" Text="Cate">
<Editor>
<ext:SelectBox runat="server">
<Items>
<ext:ListItem Text="餐饮"/>
<ext:ListItem Text="娱乐"/>
<ext:ListItem Text="电子"/>

</Items>
<DirectEvents>
<KeyUp After="selectme"></KeyUp>
</DirectEvents>
</ext:SelectBox>
</Editor>
</ext:Column>
<ext:ComponentColumn Hidden="true" ID="cc_bz" runat="server" Align="Right" Text="币别" DataIndex="bizhong" Editor="True" Width="230">
<Component>
<ext:Container ID="Container3" runat="server" Layout="HBoxLayout">
<Items>

<ext:ComboBox ID="ComboBox1" runat="server" ItemID="Currency" InputWidth="60">
<Items>
<ext:ListItem Text="USD" Value="1" Mode="Raw" />
<ext:ListItem Text="EURO" Value="2" Mode="Raw" />
</Items>
</ext:ComboBox>
<ext:TextField runat="server" InputWidth="60"></ext:TextField>
<ext:TextField runat="server" FieldLabel="原币" LabelWidth="40" InputWidth="50"></ext:TextField>
</Items>
</ext:Container>
</Component>

</ext:ComponentColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server"></ext:CellEditing>
</Plugins>
</ext:GridPanel>
</form>
</body>
</html>


please notice "selectme" event , why select a listitem from the SelectBox, why event not execute?
how to find directevent events? have docs? I notice there is no SelectBox in extjs, where to find all his directevent?

Daniil
Aug 01, 2013, 9:14 AM
Hi @tobros,

You should set up EnableKeyEvents="true" to get the key events fired.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Text-cfg-enableKeyEvents

SelectBox inherits from ComboBox. Its JavaScript source is here:
trunk\Ext.Net\Build\Ext.Net\ux\selectbox\selectbox .js

Also you can explorer its events here:
http://examples2.ext.net/#/Events/Listeners/Arguments/

tobros
Aug 01, 2013, 10:19 AM
Hi @tobros,

You should set up EnableKeyEvents="true" to get the key events fired.
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Text-cfg-enableKeyEvents

SelectBox inherits from ComboBox. Its JavaScript source is here:
trunk\Ext.Net\Build\Ext.Net\ux\selectbox\selectbox .js

Also you can explorer its events here:
http://examples2.ext.net/#/Events/Listeners/Arguments/



<ext:SelectBox runat="server" EnableKeyEvents="True">
<Items>
<ext:ListItem Text="餐饮"/>
<ext:ListItem Text="娱乐"/>
<ext:ListItem Text="电子"/>

</Items>
<DirectEvents>
<KeyUp After="selectme"></KeyUp>
</DirectEvents>
</ext:SelectBox>

dose not work, how to do when select "电子" of listitem, then trigger the event handler "selectme"

Daniil
Aug 01, 2013, 10:22 AM
You should define OnEvent here.

<KeyUp After="selectme">

It is a DirectEvent's handler.

tobros
Aug 01, 2013, 10:59 AM
You should define OnEvent here.


It is a DirectEvent's handler.



<DirectEvents>
<KeyUp OnEvent="selectme" >
</KeyUp>
</DirectEvents>

no work . vs'tip show "can not resolve the symbol onEvent"

Daniil
Aug 01, 2013, 12:51 PM
I tested it with your example. It appears to be working for me.

tobros
Aug 02, 2013, 2:27 AM
I tested it with your example. It appears to be working for me.



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm8" %>
<%@ Register TagPrefix="a" Namespace="System.Data.Entity.Migrations.Model" Assembly="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<script runat="server">


public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public string Cate { get; set; }
}


public List<Company> GetData()
{
return new List<Company>
{
new Company{ID = 1,Name = "comp1",Cate = "餐饮"},
new Company{ID = 2,Name = "comp2",Cate = "电子"},
};
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindData();

}
}
private void BindData()
{
this.store1.DataSource = GetData();
this.store1.DataBind();
}

private static bool b = true;
protected void clickme(object sender, DirectEventArgs e)
{
if (b)
{
this.cc_bz.Hidden = false;
b = false;
}
else
{
this.cc_bz.Hidden = true;
b = true;

}

}
protected void selectme(object sender, DirectEventArgs e)
{
X.Msg.Alert("sss","ddd").Show();
}

</script>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gridpanel1" Height="100">
<TopBar>

<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="show the column">
<DirectEvents>
<Click OnEvent="clickme"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="store1">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Cate"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" DataIndex="ID" Text="ID"></ext:Column>
<ext:Column ID="Column1" runat="server" DataIndex="Name" Text="NAME"></ext:Column>
<ext:Column ID="Column2" runat="server" DataIndex="Cate" Text="Cate">
<Editor>
<ext:SelectBox runat="server" EnableKeyEvents="True">
<Items>
<ext:ListItem Text="餐饮"/>
<ext:ListItem Text="娱乐"/>
<ext:ListItem Text="电子"/>

</Items>
<DirectEvents>
<KeyUp After="selectme">
</KeyUp>
</DirectEvents>
</ext:SelectBox>
</Editor>
</ext:Column>
<ext:ComponentColumn Hidden="true" ID="cc_bz" runat="server" Align="Right" Text="币别" DataIndex="bizhong" Editor="True" Width="230">
<Component>
<ext:Container ID="Container3" runat="server" Layout="HBoxLayout">
<Items>

<ext:ComboBox ID="ComboBox1" runat="server" ItemID="Currency" InputWidth="60">
<Items>
<ext:ListItem Text="USD" Value="1" Mode="Raw" />
<ext:ListItem Text="EURO" Value="2" Mode="Raw" />
</Items>
</ext:ComboBox>
<ext:TextField runat="server" InputWidth="60"></ext:TextField>
<ext:TextField runat="server" FieldLabel="原币" LabelWidth="40" InputWidth="50"></ext:TextField>
</Items>
</ext:Container>
</Component>

</ext:ComponentColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server"></ext:CellEditing>
</Plugins>
</ext:GridPanel>
</form>
</body>
</html>


no work. when the event execute?

Daniil
Aug 02, 2013, 5:13 AM
It is something old.

<KeyUp After="selectme">

Repeat myself, the OnEvent setting must be set up.

<KeyUp OnEvent="selectme">

tobros
Aug 02, 2013, 6:41 AM
It is something old.

<KeyUp After="selectme">

Repeat myself, the OnEvent setting must be set up.

<KeyUp OnEvent="selectme">




<ext:Column ID="Column2" runat="server" DataIndex="Cate" Text="Cate">
<Editor>
<ext:SelectBox runat="server" EnableKeyEvents="True">
<Items>
<ext:ListItem Text="餐饮"/>
<ext:ListItem Text="娱乐"/>
<ext:ListItem Text="电子"/>

</Items>
<DirectEvents>
<KeyUp OnEvent="selectme">
</KeyUp>
</DirectEvents>
</ext:SelectBox>
</Editor>
</ext:Column>

use this , dose not trigger the event .

Daniil
Aug 02, 2013, 6:47 AM
What are your steps? I mean what do you do to trigger this event?

tobros
Aug 02, 2013, 7:03 AM
What are your steps? I mean what do you do to trigger this event?

when I select the dropdownlist , dose not trigger

Daniil
Aug 02, 2013, 7:07 AM
Please clarify how do you select? Using keys or mouse?

tobros
Aug 02, 2013, 7:13 AM
Please clarify how do you select? Using keys or mouse?

use mouse to select

Daniil
Aug 02, 2013, 7:31 AM
KeyUp should be triggered when you releases a keyboard key. It doesn't deal with the mouse.

Probably, you should use the Select event.

tobros
Aug 02, 2013, 8:09 AM
thank you , I want to alert the selected text, but text is empty.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm8.aspx.cs" Inherits="TobrosCWT.pages.pingzheng.WebForm8" %>
<%@ Register TagPrefix="a" Namespace="System.Data.Entity.Migrations.Model" Assembly="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<script runat="server">


public class Company
{
public int ID { get; set; }
public string Name { get; set; }
public string Cate { get; set; }
}


public List<Company> GetData()
{
return new List<Company>
{
new Company{ID = 1,Name = "comp1",Cate = "餐饮"},
new Company{ID = 2,Name = "comp2",Cate = "电子"},
};
}

protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindData();

}
}
private void BindData()
{
this.store1.DataSource = GetData();
this.store1.DataBind();
}

private static bool b = true;
protected void clickme(object sender, DirectEventArgs e)
{
if (b)
{
this.cc_bz.Hidden = false;
b = false;
}
else
{
this.cc_bz.Hidden = true;
b = true;

}

}
protected void selectme(object sender, DirectEventArgs e)
{
var txt = this.sb_cate.SelectedItem.Value; // try sb_cate.SelectedItem.Text,but null.

X.Msg.Alert("sss", txt).Show();
}

</script>
<body>
<form id="form1" runat="server">
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:GridPanel runat="server" ID="gridpanel1" Height="100">
<TopBar>

<ext:Toolbar runat="server">
<Items>
<ext:Button runat="server" Text="show the column">
<DirectEvents>
<Click OnEvent="clickme"></Click>
</DirectEvents>
</ext:Button>
</Items>
</ext:Toolbar>
</TopBar>
<Store>
<ext:Store runat="server" ID="store1">
<Model>
<ext:Model runat="server" IDProperty="ID">
<Fields>
<ext:ModelField Name="ID" Type="Int" />
<ext:ModelField Name="Name" />
<ext:ModelField Name="Cate"></ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column runat="server" DataIndex="ID" Text="ID"></ext:Column>
<ext:Column ID="Column1" runat="server" DataIndex="Name" Text="NAME"></ext:Column>
<ext:Column ID="Column2" runat="server" DataIndex="Cate" Text="Cate">
<Editor>
<ext:SelectBox runat="server" EnableKeyEvents="True" ID="sb_cate">
<Items>
<ext:ListItem Text="餐饮"/>
<ext:ListItem Text="娱乐"/>
<ext:ListItem Text="电子"/>

</Items>
<DirectEvents>
<Select OnEvent="selectme">

</Select>
</DirectEvents>
</ext:SelectBox>
</Editor>
</ext:Column>
<ext:ComponentColumn Hidden="true" ID="cc_bz" runat="server" Align="Right" Text="币别" DataIndex="bizhong" Editor="True" Width="230">
<Component>
<ext:Container ID="Container3" runat="server" Layout="HBoxLayout">
<Items>

<ext:ComboBox ID="ComboBox1" runat="server" ItemID="Currency" InputWidth="60">
<Items>
<ext:ListItem Text="USD" Value="1" Mode="Raw" />
<ext:ListItem Text="EURO" Value="2" Mode="Raw" />
</Items>
</ext:ComboBox>
<ext:TextField runat="server" InputWidth="60"></ext:TextField>
<ext:TextField runat="server" FieldLabel="原币" LabelWidth="40" InputWidth="50"></ext:TextField>
</Items>
</ext:Container>
</Component>

</ext:ComponentColumn>
</Columns>
</ColumnModel>
<Plugins>
<ext:CellEditing runat="server"></ext:CellEditing>
</Plugins>
</ext:GridPanel>
</form>
</body>
</html>



how to get the selected text in the select event?

Daniil
Aug 02, 2013, 9:43 AM
A Column's Editor is not submitted automatically in POST. So, you can use ExtraParams.

Example

<Select OnEvent="OnSelect">
<ExtraParams>
<ext:Parameter Name="value" Value="records[0].data[this.valueField]" Mode="Raw" />
</ExtraParams>
</Select>


protected void OnSelect(object sender, DirectEventArgs e)
{
X.Msg.Alert("OnSelect", e.ExtraParams["value"]).Show();
}