0

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.

1
  • 1
    Define "doesn't work" - does the function fire? Look in Firebug's "Net" tab to see whether the request is made. Also, you are aware that mypage.aspx mustn't return a full HTML structure with head and `body, but only a snippet? Commented Oct 30, 2010 at 8:58

2 Answers 2

1

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">
Sign up to request clarification or add additional context in comments.

2 Comments

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 - you need some ID or class you can target in the page you're loading...otherwise you're loading all of that page.
1

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>.

Comments

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.