views:

38

answers:

2

Hello Guys,

I have a vertical left menu in my asp.net page.

using jquery .load,i try to load other aspx page in the midlle div(content div)

depending on the link click.Like this:

          $('#LeftMenu1_HyperLink1').live("click", function(event) {
             event.preventDefault();
            $("#ContentDiv").load("mypage.aspx");

        });

this solution doesn't work,i have followed the jquery doc.Do i should add some thing in mypage.aspx,all the examples i found i found googling don't work.

Can someone pls give me a working link or an example for that.

A: 

You're embedding a full HTML document into a <div> element. The result will look like this:

<html>
    <head>
    .
    .
    </head>
    <body>
        <div>
            <html>
                <head>
                .
                .
                </head>
                <body>
                .
                .
                </body>
            <html>
        </div>
    .
    .
    </body>
</html>

The browser won't be able to do anything with that. Try loading your page in an <iframe> element instead of a<div>.

Frédéric Hamidi
A: 

The best thing you can do (short of only responding with the requested content) is have a container in there, like this:

<div id="ContentDiv">
  <div id="ContentInner">
  </div>
</div>

This is to prevent multiple IDs in the page when doing the .load(). Since .load() takes a selector you'd then use that to get the content, like this:

$('#LeftMenu1_HyperLink1').live("click", function(event) {
   event.preventDefault();
   $("#ContentDiv").load("mypage.aspx #ContentInner");
});

Now this loads only that inner <div> onto this page.


Some considerations to this approach you're taking:

  • Scripts/styles in the <head> won't be loaded
  • Be sure your <form> is inside that <div id="ContentInner">
Nick Craver
Nick,Content div is not in mypage.aspx,it is in Default.aspx containg the vertical left menu.I want to load mypage.aspx into ContentDiv when the user click a the left menu element(link).Is that possible?Thanks
Cooly
@Cooly - you need some ID or class you can target in the page you're loading...otherwise you're loading *all* of that page.
Nick Craver