Menu click in user control in master page not working from content page
I had a menu in user control (menu.ascx) in master page (mainmaster.master). That menu is populated dynamically.
Now we have a content page that uses mainmaster开发者_如何学C.master has iframe. Now I want to click on menu in masterpage (which in turn is in user control) i.e products and want to open products.aspx in that iframe.
Your user control, master page and content page all get rendered to a single HTML page, so you could use client-side script to set the source of the iframe
.
Something along the lines of this:
jQuery
$(function() {
$('.menuItem').click(function(e) {
e.preventDefault();
$('#iframe').attr("src", $(this).attr("href"));
});
});
HTML
<a href="products.aspx" class="menuItem">Products</a>
<iframe id="iframe" src="default.aspx" />
Working Demo
Here's a little demo on jsfiddle.net.
精彩评论