OnClientClick for menu items possible?

J

Joe Stateson

I can add an onclick event for my asp menu using
Menu1.Attributes.Add("onclick", "jfunctioncall()"). I do not see how to add
a similar event for any of the items in the menu. Looking at the page
source I see onmouseover, onmouseout, onkeyup and was wondering if
onmouseclick could somehow be added?

=======source code=======

<asp:MenuItem Text="Select All" Value="all"></asp:MenuItem>

=====generates the following on the page====


<tr onmouseover="Menu_HoverDynamic(this)" onmouseout="Menu_Unhover(this)"
onkeyup="Menu_Key(this)" id="Menu1n3">
<td><table class="Menu1_6" cellpadding="0" cellspacing="0" border="0"
width="100%">
<tr>
<td style="white-space:nowrap;width:100%;"><a class="Menu1_1 Menu1_5"
href="javascript:__doPostBack('Menu1','Edit\\all')">Select All</a></td>
</tr>
</table></td>

=======end of code segment=====

Is there any way to make a template out of a menu item and add an item that
has some type of OnClientClick?

The only thing I can think of is to override the __doPostBack and test for
"Menu1" and "Edit\all" etc which does work but is a kluge.
 
M

Mike Placentra II

Yep, you can edit the StaticItemTemplate and DynamicItemTemplate of a
Menu control.

<asp:Menu runat="server" ...>
<StaticItemTemplate>
<asp:HyperLink ... />
</StaticItemTemplate>
</asp:Menu>

Some important DataBindings are Text and NavigateUrl.

-Mike Placentra II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top