PDA

View Full Version : [CLOSED] CheckMenuItem Click and Check events



snow_cap
Jul 12, 2014, 6:44 PM
Hi,

is it possible use CheckMenuItem and prevent the click event to be fired on check/uncheck ?
here is my case:

<ext:CheckMenuItem ID="GenerateSingle" runat="server" Text="Generate Single" Icon="PageWhite" CheckHandler="onItemCheck">
<DirectEvents>
<Click OnEvent="PublishLetterAsPdf" />
</DirectEvents>
</ext:CheckMenuItem>
i want when check/uncheck the checkbox to just call onItemCheck not PublishLetterAsPdf.

Thank you.

Daniil
Jul 14, 2014, 1:59 PM
Hi @snow_cap,

I am not sure, but it is probably possible.

Could you, please, clarify why you need both the events? It looks like they both fire on each click, don't they?

snow_cap
Jul 14, 2014, 4:27 PM
No, they aren't the same, i want when the user check the checkbox to set a HiddenField to true, then on click i want get the HiddenField value.
now if i click the menu it will always check the checkbox, so i code behind will be always true.
thank you again

Daniil
Jul 15, 2014, 12:24 PM
Well, I have not meant the events are the same, I've meat that clicking causes check/uncheck.

Ok, you want to distinguish these events.

I can suggest to override the default CheckMenuItem's onClick handler.
http://docs.sencha.com/extjs/4.2.1/source/CheckItem.html#Ext-menu-CheckItem-method-onClick

Example

<%@ Page Language="C#" %>

<script runat="server">
protected void CheckMenuItem_Click(object sender, DirectEventArgs e)
{
X.Js.Call("console.log", "CheckMenuItem_Click");
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script>
var myOnClick = function(e) {
var me = this;

if (e.getTarget("img.x-menu-item-icon-right")) {
if(!me.disabled && !me.checkChangeDisabled && !(me.checked && me.group)) {
me.setChecked(!me.checked);
}
} else {
Ext.menu.CheckItem.superclass.onClick.call(me, e);
}
};

var onItemCheck = function () {
console.log("CheckHandler");
};
</script>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Menu runat="server" Width="200" Floating="false">
<Items>
<ext:CheckMenuItem
runat="server"
Text="Item 1"
Icon="Accept"
CheckHandler="onItemCheck">
<CustomConfig>
<ext:ConfigItem Name="onClick" Value="myOnClick" Mode="Raw" />
</CustomConfig>
<DirectEvents>
<Click OnEvent="CheckMenuItem_Click" />
</DirectEvents>
</ext:CheckMenuItem>

<ext:CheckMenuItem
runat="server"
Text="Item 2"
Icon="Add"
CheckHandler="onItemCheck">
<CustomConfig>
<ext:ConfigItem Name="onClick" Value="myOnClick" Mode="Raw" />
</CustomConfig>
<DirectEvents>
<Click OnEvent="CheckMenuItem_Click" />
</DirectEvents>
</ext:CheckMenuItem>
</Items>
</ext:Menu>
</form>
</body>
</html>