Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need help!!

Need help!!

Scheduled Pinned Locked Moved ASP.NET
helpjavascripthtmlsysadmin
10 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DuckFace
    wrote on last edited by
    #1

    Hi! My problem is to reload a page that I show in an Iframe. When I press a button on one page, I want a menu (in the IFrame) to be reloaded with some new menufields. Is it possible to set a target for the menu page in code behind, e.g togheter with redirect or server.transfer. If not, how could I do this. When I use the following code with a hyperlink in the html code, it works fine, but then I don't have a onClick method, so.. href="javascript:location.reload()" target="sub_top" When I do this the menu is reloaded. Please help :) Regards...

    A 1 Reply Last reply
    0
    • D DuckFace

      Hi! My problem is to reload a page that I show in an Iframe. When I press a button on one page, I want a menu (in the IFrame) to be reloaded with some new menufields. Is it possible to set a target for the menu page in code behind, e.g togheter with redirect or server.transfer. If not, how could I do this. When I use the following code with a hyperlink in the html code, it works fine, but then I don't have a onClick method, so.. href="javascript:location.reload()" target="sub_top" When I do this the menu is reloaded. Please help :) Regards...

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi, If you just what the page in the IFrame to reload, then in the onclick handler for the button, perform something like:

      function onClkBtn1()
      {
      var elFrame = document.getElementById("idFrame1");
      if (elFrame && elFrame.contentWindow)
      {
      elFrame.contentWindow.location.reload();
      }
      }

      But if you want the contents of the menu to change, then maybe pass some querystring params to the aspx page, eg:

      function onClkBtn(el)
      {
      if (el && el.tagName == "INPUT")
      {
      idMenu = 0; // default
      switch(el.id)
      {
      case "idBtn1": idMenu = 1; break;
      case "idBtn2": idMenu = 2; break;
      case "idBtn3": idMenu = 3; break;
      }

        var elFrame = document.getElementById("idFrame1");
        if (elFrame)
        {
           elFrame.src = "generateMenu.aspx?mid=" + idMenu;
        }
      

      }
      }

      So above we have a generic handler for any buttons on the screen that need to change the menu in the IFRAME. Each has an associated Menu ID with it, remember though on the onclick handler define it as:

      <input id='idBtn1' type='button' value='Label' onclick='onClkBtn(this)'/>

      Lastly, in your generateMenu.aspx page you can quiz the querystring and decide what menus to create. Hope this helps, Andy

      D 1 Reply Last reply
      0
      • A Andrew Quinn AUS

        Hi, If you just what the page in the IFrame to reload, then in the onclick handler for the button, perform something like:

        function onClkBtn1()
        {
        var elFrame = document.getElementById("idFrame1");
        if (elFrame && elFrame.contentWindow)
        {
        elFrame.contentWindow.location.reload();
        }
        }

        But if you want the contents of the menu to change, then maybe pass some querystring params to the aspx page, eg:

        function onClkBtn(el)
        {
        if (el && el.tagName == "INPUT")
        {
        idMenu = 0; // default
        switch(el.id)
        {
        case "idBtn1": idMenu = 1; break;
        case "idBtn2": idMenu = 2; break;
        case "idBtn3": idMenu = 3; break;
        }

          var elFrame = document.getElementById("idFrame1");
          if (elFrame)
          {
             elFrame.src = "generateMenu.aspx?mid=" + idMenu;
          }
        

        }
        }

        So above we have a generic handler for any buttons on the screen that need to change the menu in the IFRAME. Each has an associated Menu ID with it, remember though on the onclick handler define it as:

        <input id='idBtn1' type='button' value='Label' onclick='onClkBtn(this)'/>

        Lastly, in your generateMenu.aspx page you can quiz the querystring and decide what menus to create. Hope this helps, Andy

        D Offline
        D Offline
        DuckFace
        wrote on last edited by
        #3

        It helps some, but I have a onClick method in the .asp.cs file that I want to execute before I reload the menu, e.g. create a Session. This is the actual problem. Is it possible to execute the javascript from the .aspx.cs file?

        A 1 Reply Last reply
        0
        • D DuckFace

          It helps some, but I have a onClick method in the .asp.cs file that I want to execute before I reload the menu, e.g. create a Session. This is the actual problem. Is it possible to execute the javascript from the .aspx.cs file?

          A Offline
          A Offline
          Andrew Quinn AUS
          wrote on last edited by
          #4

          Hi again, Well you cannot run the jscript function directly, but there is a trick you can use. Make the <BODY> a server control. Then in the server onclick handler, set the onload property of the BODY element to the JScript function you wish to run, e.g. In your HTML

          <body id="htmlBody" runat="server" MS_POSITIONING="GridLayout">
          ...
          ...
          ...
          </body>

          Then in your code behind:

          protected System.Web.UI.HtmlControls.HtmlContainerControl htmlBody;
              // ...
              // ...
              // ...
          
          private void Button1\_Click(object sender, System.EventArgs e)
          {
          	// Do what you need to do before the page is reloaded
          	// ...
          	// ...
          	// now set the onload event handler of the BODY element to 
                      // the client-side JScript function you wish to run...
          	htmlBody.Attributes\["onload"\] = "MyFunction();";
          }       
          

          So, with this in place, the page will load as normal for the first time, but when you press the button and the server-side onclick is processed, we temporarily set the client-side onload event handler to the client-side function we wish to be run. Now when the page is reloaded after the server-side onclick has finished, the MyFunction() client-side function will be run. Thus, in effect, we have run the jscript function from the server-side onclick handler We can use the HtmlContainerControl to give us a simple generic interface to the BODY element (this control proves extremely useful I've found). And we've hooked up the BODY element by making it runat="server" and matched the id with the name of the HtmlContainerControl variable name. Hope this is what you want, Andy

          D 1 Reply Last reply
          0
          • A Andrew Quinn AUS

            Hi again, Well you cannot run the jscript function directly, but there is a trick you can use. Make the <BODY> a server control. Then in the server onclick handler, set the onload property of the BODY element to the JScript function you wish to run, e.g. In your HTML

            <body id="htmlBody" runat="server" MS_POSITIONING="GridLayout">
            ...
            ...
            ...
            </body>

            Then in your code behind:

            protected System.Web.UI.HtmlControls.HtmlContainerControl htmlBody;
                // ...
                // ...
                // ...
            
            private void Button1\_Click(object sender, System.EventArgs e)
            {
            	// Do what you need to do before the page is reloaded
            	// ...
            	// ...
            	// now set the onload event handler of the BODY element to 
                        // the client-side JScript function you wish to run...
            	htmlBody.Attributes\["onload"\] = "MyFunction();";
            }       
            

            So, with this in place, the page will load as normal for the first time, but when you press the button and the server-side onclick is processed, we temporarily set the client-side onload event handler to the client-side function we wish to be run. Now when the page is reloaded after the server-side onclick has finished, the MyFunction() client-side function will be run. Thus, in effect, we have run the jscript function from the server-side onclick handler We can use the HtmlContainerControl to give us a simple generic interface to the BODY element (this control proves extremely useful I've found). And we've hooked up the BODY element by making it runat="server" and matched the id with the name of the HtmlContainerControl variable name. Hope this is what you want, Andy

            D Offline
            D Offline
            DuckFace
            wrote on last edited by
            #5

            Hi! Now I can run a jscript from the cs file. Thanks... I'm not good with jscript. Do you know how a javascript can reload a page and target it to a given IFRAME or do you know of a good site on javascripts (I tried using the one you sent earlier. Did'nt get it to work. Nothing happend when I ran it. I changed the id to my IFRAME id, but nothing happend). When I ran the script I could use with the hyperlink (see above) I got an error that said the page could'nt be refreshed without resending the information and I had to press retry or cancel. Nothing happend when I clicked either retry or cancel. I had to end the task in taskmanager. You've helped me a lot. If you can help me with this one too, I'll be eternaly grateful.

            A 1 Reply Last reply
            0
            • D DuckFace

              Hi! Now I can run a jscript from the cs file. Thanks... I'm not good with jscript. Do you know how a javascript can reload a page and target it to a given IFRAME or do you know of a good site on javascripts (I tried using the one you sent earlier. Did'nt get it to work. Nothing happend when I ran it. I changed the id to my IFRAME id, but nothing happend). When I ran the script I could use with the hyperlink (see above) I got an error that said the page could'nt be refreshed without resending the information and I had to press retry or cancel. Nothing happend when I clicked either retry or cancel. I had to end the task in taskmanager. You've helped me a lot. If you can help me with this one too, I'll be eternaly grateful.

              A Offline
              A Offline
              Andrew Quinn AUS
              wrote on last edited by
              #6

              Hi again, Perhaps try the following:

              function onMyClk()
              {
              var url = "http://news.bbc.co.uk"; // for example
              var elFrame = document.getElementById("idFrame1");
              if (elFrame)
              {
              // date and time right now
              var dt = new Date();
              // get the UTC
              id = Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds());
              // navigate to unique page
              elFrame.src = url + "?{532B04B8-014D-43e0-A9F3-5FCD44DA60B8}=" + id;
              }
              }

              So we are navigating to the same page, but the difference is that we are generating a unique page request because we use a unique query string value. The query string name is a GUID I just generated, the value is the number of milliseconds since midnight January 1st 1970. The two combined are guaranteed to be unique. Make sure the <IFRAME> element has the id "idFrame1" or change the code above to reflect whatever the id you want is. Hope this helps, Andy

              D 1 Reply Last reply
              0
              • A Andrew Quinn AUS

                Hi again, Perhaps try the following:

                function onMyClk()
                {
                var url = "http://news.bbc.co.uk"; // for example
                var elFrame = document.getElementById("idFrame1");
                if (elFrame)
                {
                // date and time right now
                var dt = new Date();
                // get the UTC
                id = Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds());
                // navigate to unique page
                elFrame.src = url + "?{532B04B8-014D-43e0-A9F3-5FCD44DA60B8}=" + id;
                }
                }

                So we are navigating to the same page, but the difference is that we are generating a unique page request because we use a unique query string value. The query string name is a GUID I just generated, the value is the number of milliseconds since midnight January 1st 1970. The two combined are guaranteed to be unique. Make sure the <IFRAME> element has the id "idFrame1" or change the code above to reflect whatever the id you want is. Hope this helps, Andy

                D Offline
                D Offline
                DuckFace
                wrote on last edited by
                #7

                Well! The script doesn't enter the if statement. Does the getElementById get any element in the application. Because, I want to update the menu from a different page in a different IFRAME. If not, how can I set witch page the getElement method should "search" in.

                A 1 Reply Last reply
                0
                • D DuckFace

                  Well! The script doesn't enter the if statement. Does the getElementById get any element in the application. Because, I want to update the menu from a different page in a different IFRAME. If not, how can I set witch page the getElement method should "search" in.

                  A Offline
                  A Offline
                  Andrew Quinn AUS
                  wrote on last edited by
                  #8

                  Hi, I'm confused. The script is to (re)load an iframe element in the current web page, i.e. the script and the iframe element in the same physical web page. If you are talking about a script in the page that the ifram contains - you can execute scripts in your parent window (the page with the iframe element) by:

                  function callParentScript()
                  {
                  if (window.parent && window.parent.onMyClk)
                  {
                  window.parent.onMyClk();
                  }
                  }

                  This script checks that we have a parent window (should be true for a page contained within an iframe, and that this parent window has a function called onMyClk, if so it calls it. There are some gotchas with all this voodoo - if the child window and the parent window reside in different domains, then access to either or is limited (at least in IE5.5 SP2 and above) this is called cross-frame scripting and is home to those blomin' script kiddies - so Microsoft has limited the ability to only allow pages in the same domain to perform such actions, i.e. trusted pages. If this still isn't what you are looking for, perhaps show me a snippet of your pages so I can get the gist of what your page structure is like. Hope this helps, Andy

                  D 1 Reply Last reply
                  0
                  • A Andrew Quinn AUS

                    Hi, I'm confused. The script is to (re)load an iframe element in the current web page, i.e. the script and the iframe element in the same physical web page. If you are talking about a script in the page that the ifram contains - you can execute scripts in your parent window (the page with the iframe element) by:

                    function callParentScript()
                    {
                    if (window.parent && window.parent.onMyClk)
                    {
                    window.parent.onMyClk();
                    }
                    }

                    This script checks that we have a parent window (should be true for a page contained within an iframe, and that this parent window has a function called onMyClk, if so it calls it. There are some gotchas with all this voodoo - if the child window and the parent window reside in different domains, then access to either or is limited (at least in IE5.5 SP2 and above) this is called cross-frame scripting and is home to those blomin' script kiddies - so Microsoft has limited the ability to only allow pages in the same domain to perform such actions, i.e. trusted pages. If this still isn't what you are looking for, perhaps show me a snippet of your pages so I can get the gist of what your page structure is like. Hope this helps, Andy

                    D Offline
                    D Offline
                    DuckFace
                    wrote on last edited by
                    #9

                    That did the trick! I can not thank you enough! Have a great day:) (It's early here (Germany), but I'm from Norway)

                    A 1 Reply Last reply
                    0
                    • D DuckFace

                      That did the trick! I can not thank you enough! Have a great day:) (It's early here (Germany), but I'm from Norway)

                      A Offline
                      A Offline
                      Andrew Quinn AUS
                      wrote on last edited by
                      #10

                      That's okay - glad to be of help. Take care, Andy

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups