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
  1. Home
  2. Web Development
  3. Show/hide Div tag in popup window???

Show/hide Div tag in popup window???

Scheduled Pinned Locked Moved Web Development
javascriptquestion
9 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    vicky457
    wrote on last edited by
    #1

    Hi all, I have a div tag in my user control, and I want to show/hide this div based on which page I am on. So here is what I have now. in .ascx page,

    ....content

    in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { class= "CssHideDiv"; } return class; } The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv. Can anybody give me a hint what's wrong with my code? Thank you very much!

    G 1 Reply Last reply
    0
    • V vicky457

      Hi all, I have a div tag in my user control, and I want to show/hide this div based on which page I am on. So here is what I have now. in .ascx page,

      ....content

      in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { class= "CssHideDiv"; } return class; } The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv. Can anybody give me a hint what's wrong with my code? Thank you very much!

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Half of your code doesn't show up. Use the "Ignore HTML" option when you are posting markup code.

      Experience is the sum of all the mistakes you have done.

      V 1 Reply Last reply
      0
      • G Guffa

        Half of your code doesn't show up. Use the "Ignore HTML" option when you are posting markup code.

        Experience is the sum of all the mistakes you have done.

        V Offline
        V Offline
        vicky457
        wrote on last edited by
        #3

        Hi all, I have a div tag in my user control, and I want to show/hide this div based on which page I am on. So here is what I have now. in .ascx page,

        ....content

        in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { class= "CssHideDiv"; } return class; } The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv. Can anybody give me a hint what's wrong with my code? Thank you very much!

        M G 2 Replies Last reply
        0
        • V vicky457

          Hi all, I have a div tag in my user control, and I want to show/hide this div based on which page I am on. So here is what I have now. in .ascx page,

          ....content

          in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { class= "CssHideDiv"; } return class; } The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv. Can anybody give me a hint what's wrong with my code? Thank you very much!

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          I guess, maybe. the path of CSS file in popup window is wrong??

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

          1 Reply Last reply
          0
          • V vicky457

            Hi all, I have a div tag in my user control, and I want to show/hide this div based on which page I am on. So here is what I have now. in .ascx page,

            ....content

            in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { class= "CssHideDiv"; } return class; } The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv. Can anybody give me a hint what's wrong with my code? Thank you very much!

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            vicky457 wrote:

            in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv";

            No, that's not the code that you are using. You can't name a variable "class", so that code doesn't even compile. Show the code that you are actually using. I can't see what's wrong with the code that you are using by looking at some other code that you are not using.

            vicky457 wrote:

            if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0)

            If you have as condition that the value that IndexOf returns should be greater than zero, that means that if the string is found at the first position in the url, the condition will be false. Not that the url is likely to be only the page name, but you should be aware of it.

            vicky457 wrote:

            The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv.

            The server isn't even aware that the page will be shown in a popup, and none of the code that you have shown would act any different in a popup, so the problem is in some of the code that you haven't shown.

            Experience is the sum of all the mistakes you have done.

            V M 2 Replies Last reply
            0
            • G Guffa

              vicky457 wrote:

              in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv";

              No, that's not the code that you are using. You can't name a variable "class", so that code doesn't even compile. Show the code that you are actually using. I can't see what's wrong with the code that you are using by looking at some other code that you are not using.

              vicky457 wrote:

              if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0)

              If you have as condition that the value that IndexOf returns should be greater than zero, that means that if the string is found at the first position in the url, the condition will be false. Not that the url is likely to be only the page name, but you should be aware of it.

              vicky457 wrote:

              The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv.

              The server isn't even aware that the page will be shown in a popup, and none of the code that you have shown would act any different in a popup, so the problem is in some of the code that you haven't shown.

              Experience is the sum of all the mistakes you have done.

              V Offline
              V Offline
              vicky457
              wrote on last edited by
              #6

              I have the following in .aspx page: The OpenSuin .js file function OpenSummaryPage() { with(aspnetForm) { var url ="summary.aspx?comment=" + hdShowComment.value; window.open(url); } } The function in ascx.cs page is actually like this: public string ReturnVisibility() { string divCssClass= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { divCssClass= "CssHideDiv"; } return divCssClass; } In .css file: .CssShowDiv{DISPLAY: true} .CssHideDiv{DISPLAY: none} Thanks for help!

              G 1 Reply Last reply
              0
              • V vicky457

                I have the following in .aspx page: The OpenSuin .js file function OpenSummaryPage() { with(aspnetForm) { var url ="summary.aspx?comment=" + hdShowComment.value; window.open(url); } } The function in ascx.cs page is actually like this: public string ReturnVisibility() { string divCssClass= "CssShowDiv"; if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0) { divCssClass= "CssHideDiv"; } return divCssClass; } In .css file: .CssShowDiv{DISPLAY: true} .CssHideDiv{DISPLAY: none} Thanks for help!

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                vicky457 wrote:

                The javascript: protocol is only used if you put the Javascript in an url. If you use it anywhere else, it isn't recognised as a protocol but it becomes a label instead. As you are using xhtml, argument names have to be lower case. <img src="btn_print.gif" onclick="OpenSummaryPage();"/>

                vicky457 wrote:

                var url ="summary.aspx?comment=" + hdShowComment.value;

                Use the getElementById to access elements in the page. var url = "summary.aspx?comment=" + document.getElementById('hdShowComment').value;

                vicky457 wrote:

                .CssShowDiv{DISPLAY: true}

                "true" is not a valid value for the display style. Use the value "block" to display a block element (e.g. a div) and the value "inline" to display an inline element (e.g. a span). Have you verified that the css really is used on the page? You can for example add a background color or a border to some element on the page to see if it's used. Css files are cached longer than pages, so an older version of the css file might be used. Press ctrl+F5 to reload the page and all files it uses.

                Experience is the sum of all the mistakes you have done.

                V 1 Reply Last reply
                0
                • G Guffa

                  vicky457 wrote:

                  in ascx.cs page: public string ReturnVisibility() { string class= "CssShowDiv";

                  No, that's not the code that you are using. You can't name a variable "class", so that code doesn't even compile. Show the code that you are actually using. I can't see what's wrong with the code that you are using by looking at some other code that you are not using.

                  vicky457 wrote:

                  if (Page.Request.Url.ToString().IndexOf("page1.aspx") > 0)

                  If you have as condition that the value that IndexOf returns should be greater than zero, that means that if the string is found at the first position in the url, the condition will be false. Not that the url is likely to be only the page name, but you should be aware of it.

                  vicky457 wrote:

                  The result is that it works fine in a normal window. But if I open the page in a popup window using javascript, the div tag content always shows on the page, even though the class is CssHideDiv.

                  The server isn't even aware that the page will be shown in a popup, and none of the code that you have shown would act any different in a popup, so the problem is in some of the code that you haven't shown.

                  Experience is the sum of all the mistakes you have done.

                  M Offline
                  M Offline
                  Michael Sync
                  wrote on last edited by
                  #8

                  Guffa wrote:

                  No, that's not the code that you are using.

                  good caught... I didn't notice that one.. great answer..

                  Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) "Please vote to let me (and others) know if this answer helped you or not. A 5 vote tells people that your question has been answered successfully and that I've pitched it at just the right level. Thanks."

                  1 Reply Last reply
                  0
                  • G Guffa

                    vicky457 wrote:

                    The javascript: protocol is only used if you put the Javascript in an url. If you use it anywhere else, it isn't recognised as a protocol but it becomes a label instead. As you are using xhtml, argument names have to be lower case. <img src="btn_print.gif" onclick="OpenSummaryPage();"/>

                    vicky457 wrote:

                    var url ="summary.aspx?comment=" + hdShowComment.value;

                    Use the getElementById to access elements in the page. var url = "summary.aspx?comment=" + document.getElementById('hdShowComment').value;

                    vicky457 wrote:

                    .CssShowDiv{DISPLAY: true}

                    "true" is not a valid value for the display style. Use the value "block" to display a block element (e.g. a div) and the value "inline" to display an inline element (e.g. a span). Have you verified that the css really is used on the page? You can for example add a background color or a border to some element on the page to see if it's used. Css files are cached longer than pages, so an older version of the css file might be used. Press ctrl+F5 to reload the page and all files it uses.

                    Experience is the sum of all the mistakes you have done.

                    V Offline
                    V Offline
                    vicky457
                    wrote on last edited by
                    #9

                    I just found out the problem is caused by a stupid mistake. There is duplicated CssClass is defined, one is in Master page and is called CssHideDiv, the other is in .css file and is called CssHiddenDiv. The open widnow is not using master page, but is using CssHideDiv. This is a mistake introduced by multiple developers defining the same css class. Thanks for everybody's help! I appreciate it!

                    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