Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I execute this instruction IdDiv.Style.Add ("display", "block") from another aspx?
Div is on page1.aspx I want to reference on page2.aspx.
the instruction works without problems but on the page where the Div is located

What I have tried:

IdDiv.Style.Add ("display", "block") 


<%--head--%>
 <div id="IdDiv" runat="server"  style=" visibility:visible ;HEIGHT: 100%; WIDTH: 100%; POSITION: absolute; LEFT: 0px; FILTER: alpha(opacity=50);; Z-INDEX: 2490; TOP: 0px; BACKGROUND-COLOR: threedshadow; opacity: 0.5"></div>
Posted
Updated 18-Dec-17 1:55am

Pages only exist when the user requests them, so you can't update one from another. Instead store something in the Session if the div on page2 needs updating;

Session("MakeBlock") = True


Then on page2's load event check that Session value and if it exists and is True then add the style then, and set the Session variable to Nothing.
 
Share this answer
 
Comments
Member 12554029 15-Dec-17 5:21am    
what I do is launch page 2 from page 1, page 1 activates div as well: div.Style.Add ("display", "block") and page2 deactivates it by making a div.Style.Add (" display "," none ")
F-ES Sitecore 15-Dec-17 6:11am    
Launch the page how? A link? window.open? an iframe? You have to remember we can't access your system, we only know what you tell us. You could add a parameter to the url of page2 if it needs to change the style, so

page2.aspx?block=true

and use that to decide if the style is added or not.
Member 12554029 15-Dec-17 6:32am    
The way to launch the page is as follows:
on page1.aspx.vb I put this:
Dim newWin As String = "window.open ('page2.aspx', '_blank', 'top = 300, left = 400, width = 700, height = 500, status = yes')" ClientScript.RegisterStartupScript (Me.GetType (), "popup", newWin, True)
F-ES Sitecore 15-Dec-17 6:51am    
So add the param to the querystring if it's needed, and change page2 to access the param and add the style if it is there.
Member 12554029 15-Dec-17 7:49am    
How could I do that?
Page1

<body>
    <form id="form1" runat="server">
        <div id="IdDiv" runat="server"  style=" visibility:visible ;HEIGHT: 100%; WIDTH: 100%; POSITION: absolute; LEFT: 0px; FILTER: alpha(opacity=50);; Z-INDEX: 2490; TOP: 0px; BACKGROUND-COLOR: threedshadow; opacity: 0.5">
            Page1
        </div>
    </form>

    <script type="text/javascript">
        function hideDiv() {
            var div = document.getElementById('<%=IdDiv.ClientID%>');
            div.style.display = 'none';
        }
    </script>
</body>


Page2

<body>
    <form id="form1" runat="server">
        <div>
            Page2
        </div>
    </form>

    <script type="text/javascript">
        window.addEventListener('beforeunload', function (event) {
            window.opener.hideDiv();
        });

    </script>
</body>
 
Share this answer
 
Comments
Member 12554029 18-Dec-17 4:59am    
the scripst do not work for me, they do not hide the background, the page1 that is where the Div to hide has this escript


function hideDiv () {
var div = document.getElementById ('&lt;% = background.ClientID%>');
div.style.display = 'none';

<pre>
}
&lt;/ script&gt;</pre>


and the page that closes and must give the order to hide it has this other

<script type = "text / javascript">
window.attachEvent ('beforeunload', function (event) {
window.opener.hideDiv ();
});

<pre>
&lt;/ script&gt;</pre>
the scripst do not work for me, they do not hide the background, the page1 that is where the Div to hide has this escript
<script type = "text / javascript">
         function hideDiv () {
             var div = document.getElementById ('<% = background.ClientID%>');
             div.style.display = 'none';

         }
    </ script>

and the page that closes and must give the order to hide it has this other
<script type = "text / javascript">
          window.attachEvent ('beforeunload', function (event) {
             window.opener.hideDiv ();
         });
 
     </ script>
 
Share this answer
 
solved: corrected some errors of the scripst
Thank you very much for the contribution.
page 2

<script type = "text / javascript">
          window.attachEvent ('onbeforeunload', function (event) {
              window.opener.hideDiv ();
             
         });
 
     </ script>

page 1

<script type = "text / javascript">
          function hideDiv () {
             var div = document.getElementById ('<% = IdDiv.ClientID%>');
             div.style.display = 'none';
            
          }

     </ script>
 
Share this answer
 
I have a problem with this solution, it works perfectly but when I hit any button the div hides me, how can I make it only when I close the windows?
 
Share this answer
 
Comments
F-ES Sitecore 18-Dec-17 7:59am    
There's no way of knowing when the user closes a browser, that's one of the many reasons why this type of solution is bad and you never see it on other sites. You don't have any real control over what the client does on their machine or with their browser.
Member 12554029 18-Dec-17 8:28am    
there has to be a secure window close sign for some place, i'm use OnClientClick = "window.close(); for close windows
Richard Deeming 18-Dec-17 14:00pm    
If you want to comment on a solution, click the "Have a Question or Comment?" button under that solution.

DO NOT post your comment as a new "solution"!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900