Logged events:
Source Code & Description
Much like the event handling exposed by the Document Object Model, the
client-side RadMenu object allows both singlecast and multicast event
handler binding.
-
Singlecast event handling
The singlecast event handling is the simplest way to execute user code when an
event occurs. It is done by a direct assignment.
<script type="text/javascript">
function OnClicking(sender, eventArgs)
{
if (eventArgs.Item.NavigateUrl != "")
{
var proceed = confirm("Navigate to "+ eventArgs.Item.NavigateUrl + " ?");
if (!proceed)
{
return false;
}
}
}
</script>
<radM:RadMenu ID="RadMenu1" runat="server" OnClientItemClicking="OnClicking"></>
-
Multicast event handling If you want multiple listeners to respond to a certain
event, you should use multicast event handling. The example below demonstrates
how to bind multiple event handlers to the OnClientItemClicked event of the
menu.
<script type="text/javascript">
function OnClickedHandler1()
{
alert("first handler called");
}
function OnClickedHandler2()
{
alert("second handler called");
}
RadMenu1.AttachEvent("OnClientItemClicked", OnClickedHandler1);
RadMenu1.AttachEvent("OnClientItemClicked", OnClickedHandler2);
</script>
Another advantage of multicast event handlers is the possiblity of detaching a
certain handler dynamically. You may use the DetachEvent method of
the menu object.
<script type="text/javascript">
RadMenu1.DetachEvent("OnClientItemClicked", OnClickedHandler1);
</script>
-
Event hanlders formatting To conform with the Document Object Model we have
exposed 3 available formats for event handler definition. These formats are
supported both for singlecast and multicast event handling.
-
Function reference First you define a function, then you pass a reference to
it.
<script type="text/javascript">
function OnClickedHandler()
{
alert("first hadler called");
}
RadMenu1.OnClientItemClicked = OnClickedHandler;
</script>
-
Function name (string) First you define a function, then you pass its name as
an event handler.
<script type="text/javascript">
function OnClickedHandler()
{
alert("first hadler called");
}
RadMenu1.OnClientItemClicked = "OnClickedHandler";
</script>
-
String containing executable code Useful for simple scenarios. The string
passed is evaluated when the event handler is called.
<script type="text/javascript">
RadMenu1.OnClientItemClicked = "alert('first hadler called')";
</script>
-
Cancelling an event
In general, the events which are named with ing suffix (OnClientItemClicking
for instance), can be cancelled if you explicitly return false from
a handler. The following code cancels a menu item selection:
<script type="text/javascript">
function OnClientItemClickingHandler()
{
alert("item not clicked");
return false;
}
RadMenu1.OnClientItemClicking = "OnClientItemClickingHandler";
</script>
