Attaching "OnClick" event to <asp:menu.../> menu item.
After googling, I found out that there is no way to attach "OnClick" event to menu item in code behind. Then only way it could be done is by javascript. Luckily, I have to attach same functionality to all menu items (small animation when page is being posted
back and waiting ..)
<body>
<form ...>
<img id="menuWaiter" src="/CStore/Images/processing.gif" alt="" style="display:none"/>
<asp:Menu ID="menuMain" runat="server".../>
//I used SiteMapDataSource to bind this control
<script type="text/javascript">
var varMenuMain = '<%= menuMain.ClientID %>'
var elements = document.getElementById(varMenuMain).getElementsByTagName('a');
for (var i = 0; i < elements.length; i++)
{
if(elements[i].href != "")
{
if (navigator.appName == 'Microsoft Internet Explorer')
{
elements[i].attachEvent('onclick', Animation)
}
else
{
elements[i].addEventListener('click', Animation, false)
}
}
}
</script>
</form>
</body>
There are two script sections, one in the head and one at the end (but before the page ends). <asp:menu ...> is rendered as "div" and all its menu items are rendered as anchors "a".
This technique works when you have to do full post back and the connection is slow or service response time is higher. While the client is waiting for the fresh page, client browser will show the animation.
Replies.AsEnumerable()
.Where(rep =>rep.YouLookingFor.Equals('helpjet'))
.Select (new {Mark As Answer = 'helpjet'})
Member
207 Points
450 Posts
Attaching "OnClick" event to <asp:Menu ..>
Mar 08, 2011 07:01 PM|helpjet|LINK
Attaching "OnClick" event to <asp:menu.../> menu item.
After googling, I found out that there is no way to attach "OnClick" event to menu item in code behind. Then only way it could be done is by javascript. Luckily, I have to attach same functionality to all menu items (small animation when page is being posted back and waiting ..)
Here is the html
There are two script sections, one in the head and one at the end (but before the page ends). <asp:menu ...> is rendered as "div" and all its menu items are rendered as anchors "a".
This technique works when you have to do full post back and the connection is slow or service response time is higher. While the client is waiting for the fresh page, client browser will show the animation.
Replies.AsEnumerable()
.Where(rep =>rep.YouLookingFor.Equals('helpjet'))
.Select (new {Mark As Answer = 'helpjet'})