0

I am using ASP Menu control with a collection of sub menu items. If user clicks on main menu item it reloads and the screen makes a postback. It irritates the user when clicks on main menu as it is only to list out the categories. How to prevent the loading of page when user clicks on main menu item I tried some code using javascript but its not working.

My ASP menu control:

<asp:Menu ID="mini" OnMenuItemClick="mini_MenuItemClick" runat="server" Orientation="Horizontal" >
    <Items>
        <asp:MenuItem Text="Items">
            <asp:MenuItem Text="sdaad" Value="1" >
                <asp:MenuItem Text="MenuSub1"  Value="MenuSub1" ></asp:MenuItem>
                <asp:MenuItem Text="MenuSub2" Value="MenuSub2" ></asp:MenuItem>
            </asp:MenuItem>
            <asp:MenuItem Text="qwerty" Value="qwerty">
                <asp:MenuItem Text="MenuSub" Value="MenuSub"></asp:MenuItem>
            </asp:MenuItem>
        </asp:MenuItem>
    </Items>
</asp:Menu>

Javascript to handle the issue:

function OnMenuItemClick(s, e) {
    if (e.item.name == "Items")
        e.processOnServer = false;
}
2
  • 1
    You might want to look at asp:updatepanel Commented Dec 15, 2015 at 9:18
  • Can you please briefly explain it Commented Dec 15, 2015 at 9:35

1 Answer 1

1

First, put update panel in markup

<asp:UpdatePanel runat="server" id="Update" UpdateModel="Conditional">
</UpdatePanel>

Then use javascript to trigger it:

__doPostBack(<%# Update.ClientID%>, '');
Sign up to request clarification or add additional context in comments.

5 Comments

Where should I add java script code and update control. Sorry I am new to asp.net
The control with ID 'Update' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.
Then add <asp:ScriptManager runat="server"/>
Now javascript code is not working <script type="text/javascript"> _doPostBack(<%# Update.ClientID%>, 'Items');</script>
Now I got this error The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.