Results 1 to 6 of 6

Thread: calling ajaxpage function without any event handler

  1. #1
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default calling ajaxpage function without any event handler

    1) Script Title:
    Dynamic Ajax Content

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...jaxcontent.htm

    3) Describe problem:

    Hi,

    I just tried the pervious code to dynamically change the content of a div with an external web page

    it works fine when I call the function ajaxpage with an event handler like

    Code:
        <body dir="rtl" onload="javascript:ajaxpage('Main.aspx', 'D1'); return false;" >
    but when I want to call it within the code or within another javascript function it doesn't work !!

    what is the problem

    this is a part of my code


    Code:
    <%
        Dim P As String
        P = Trim(Request("p"))
    %>
    
    
    <script type="text/javascript">
    
        function redir(MyD) {
    
           switch (MyD)
           {
                case '': ajaxpage('Main.aspx.vb', 'D1');  break;
                case 'Main': ajaxpage('Main.aspx.vb', 'D1'); break;
                case 'WhoWeAre': ajaxpage('WhoWeAre.aspx.vb', 'D1'); break;
                case 'Products': ajaxpage('Products.aspx.vb', 'D1'; break;
                case 'Services': ajaxpage('Services.aspx.vb', 'D1'); break;
                case 'Distributors': ajaxpage('Distributors.aspx.vb', 'D1'); break;
                case 'Offers': ajaxpage('Offers.aspx.vb', 'D1') break;
                case 'HowToOrder': ajaxpage('HowToOrder.aspx.vb', 'D1');break;
                case 'ContactUs': ajaxpage('ContactUs.aspx.vb', 'D1'); break;
                default: ajaxpage('ERR.aspx.vb', 'D1');
            }
        }
    
    </script>
    
               
    <head runat="server">
        <title>My Page</title>
    </head>
        <body dir="rtl" onload="javascript:redir('<%=P%>');return false; ">
    any idea

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This type of AJAX import generally doesn't import your javascript in a functional manner, though (as you've observed) javascript events associated with HTML tags generally will fire. You could -

    (1) Put the javascript on the 'top' page (the same page that has the ajaxpage function on or linked to it).

    OR -

    (2) Try using this as the event in the body tag:

    Code:
    <body dir="rtl" onload="ajaxpage(('<%=P%>' || 'Main') + '.aspx.vb', 'D1');">
    It will cover all the case statements from your javascript code except for the default one, which I assume is there in case somehow a page name other than none or those you are anticipating gets passed as Trim(Request("p")). If this is at all likely to happen, my first suggestion would be the better method.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    Mashael (10-19-2009)

  4. #3
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot John,

    The second method worked great

    But still I want to try the first one, what do you mean by the TOP Page??
    Both of the two functions are defined in the same JavaScript block in the Default page before the head tag,

    did you mean something else ?

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Without actually seeing your pages, I'm assuming that you have one or more pages (these we will represent as the 'top' page(s)) that can bring in the code from your post via the ajaxpage function. The code from your post then in turn brings in yet another page via the ajaxpage function based upon the get or post value of p.

    If I have that right, now you know where the top page is.

    Incidentally, this:

    Code:
    <%
        Dim P As String
        P = Trim(Request("p"))
    %>
    and this:

    Code:
    <%=P%>
    is server side code, asp or something similar. It runs on the server side as the page is served. The rest of the script code is javascript and runs only as parsed by the browser on the client side.

    The tricky part is, a script like so:

    Code:
    <script type="text/javascript">
    
        function redir(MyD) {
    
           switch (MyD)
           {
                case '': ajaxpage('Main.aspx.vb', 'D1');  break;
                case 'Main': ajaxpage('Main.aspx.vb', 'D1'); break;
                case 'WhoWeAre': ajaxpage('WhoWeAre.aspx.vb', 'D1'); break;
                case 'Products': ajaxpage('Products.aspx.vb', 'D1'; break;
                case 'Services': ajaxpage('Services.aspx.vb', 'D1'); break;
                case 'Distributors': ajaxpage('Distributors.aspx.vb', 'D1'); break;
                case 'Offers': ajaxpage('Offers.aspx.vb', 'D1') break;
                case 'HowToOrder': ajaxpage('HowToOrder.aspx.vb', 'D1');break;
                case 'ContactUs': ajaxpage('ContactUs.aspx.vb', 'D1'); break;
                default: ajaxpage('ERR.aspx.vb', 'D1');
            }
        }
    
    </script>
    will not run on either side. If it is run by the server, there is no function ajaxpage() so there would be an error. And, due to the way that the ajaxpage function works, if this code itself is imported via the ajaxpage function (which I'm just guessing that it is) it just won't run or be seen as javascript. But if it was on what I'm calling the top page, it will be accessible to events on imported content.

    Now, there are other possibilities as to how your site is organized in this regard, so I may be misunderstanding what's happening. So if you want more help on this:

    Please post a link to the page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #5
    Join Date
    Oct 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi again,

    I really appreciate the explanation ; even I think I didn't get it all
    And my site still in my PC, I’m using Microsoft Visual Web Developer 2008 Express Edition

    I have solve the default situation by butting a span inside the div, which will run in case of non of the presented cases was occured

    Forgive me for my questions but I have a one last:
    I attempted to have a JavaScript drop-down menu which will have a buttons which use the ajaxpage function, Do you think it will work??

  7. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by Mashael View Post
    I think I didn't get it all
    That may mean that I didn't get it all. Without seeing the live site I can only guess at some of the things I was saying. I tried to indicate that some it was just guessing. If that didn't come across, let me be clearer - I was just guessing at some of it.

    As to your menu idea, perhaps. I really cannot be sure because I'm really not sure what you are proposing, though something like that can work if it is done correctly.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •