Solved

ASP.NET window.showModalDialog change parent window background color

Posted on 2009-04-04
9
2,985 Views
Last Modified: 2012-05-06
How can I change the background of the parent window when I use the window.showModalDialog to open a modal pop up in a datalist? Somewhat similar to what the ASP.NET AJAX Modal Popup extender provides. I have provided code snippets below.

Thank you
<script language ="javascript" type ="text/javascript">
 
function ShowModalWindow(Id)
                  {
                        window.showModalDialog("photo-gallery.aspx?gid="+ Id +"","","status:no;dialogWidth:800px;dialogHeight:570px;help:no;center:yes;resizable:no;scroll:yes;status:no;");
                  }
</script>
 
<asp:DataList ID="dtlgalleries"
   OnItemDataBound="dtlgalleries_ItemDataBound"	
   BorderStyle="Solid" 
   BorderWidth="1px"  
   runat="server"  
   RepeatColumns="4" 
   RepeatDirection="Horizontal" 
   Width="700px" 
   DataKeyField="Gallery_ID" 
   AllowPaging="True"
   AllowCustomPaging="True"
   PageSize="4"
   PagerStyle-Visible="False">
                <ItemTemplate>
                
                    <p class="photo_cover"><br /><asp:LinkButton ID="LinkButtonImg" runat="server" Text=''><img style="border-width:2px; border-style:solid; border-color:#666666;" alt="" src="images/gallery/thumb/<%# Eval("Gallery_Image") %>" /></asp:LinkButton></p>
                    <p class="photos_title"><asp:LinkButton ID="LinkButtonTxt" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Gallery_Caption") %>'></asp:LinkButton><br />[# of Slides: <%# Eval("PhotoCount") %>]</p>               
                                
                </ItemTemplate>
                <ItemStyle VerticalAlign="Top" />
            </asp:DataList>  
 
 
Sub dtlgalleries_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
        Dim btn, btnImg As LinkButton
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            btn = CType(e.Item.FindControl("LinkButtonTxt"), LinkButton)
            btnImg = CType(e.Item.FindControl("LinkButtonImg"), LinkButton)
 
            If DataBinder.Eval(e.Item.DataItem, "PhotoCount") > 0 Then
                btnImg.Attributes.Add("onclick", "ShowModalWindow('" & DataBinder.Eval(e.Item.DataItem, "Gallery_Id") & "')")
                btn.Attributes.Add("onclick", "ShowModalWindow('" & DataBinder.Eval(e.Item.DataItem, "Gallery_Id") & "')")
            End If
 
            '<a href='#' onclick = "ShowModalWindow('<%# DataBinder.Eval(Container.DataItem,"Gallery_Id") %>');"><%# Eval("Gallery_Caption") %>
 
 
        End If
    End Sub

Open in new window

0
Comment
Question by:DeMyu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
9 Comments
 
LVL 1

Expert Comment

by:Shyam_Saraf
ID: 24070339
Try this --

function ShowModalWindow(Id)
                  {

document.bgColor='#CCCC99'; // change the colur combination of your choice
                        window.showModalDialog("photo-gallery.aspx?gid="+ Id +"","","status:no;dialogWidth:800px;dialogHeight:570px;help:no;center:yes;resizable:no;scroll:yes;status:no;");
                  }


0
 

Author Comment

by:DeMyu
ID: 24072986
I'm afraid that will only change the background of the child window. I will like to change the background of the parent window on popup and to revert it back to its original state on closing the child window.

Thank you.
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 24091757
1. If you want to change the background color of the parent window, then you will need to use window.open method. This method will give you a handler to the parent window, but window.showModalDialog will not give you the handler and you cannot connect to the parent window through the child window.
2. Even you can change the parent window when the child window is popped up, it is impossible to change the background color of the parent window back to the previous window. The reason is simple: user can close the child window by clicking the "X" button of the child window, which will not be detected by your code.
Anyway, to change the parent window's background color, change
window.showModalDialog(....)
To
window.open(...)
Then in your child window, create a JavaScript function like this:

<script type="text/javascript">
function checkParent()
{
var par = window.parent.opener;
if (par != null)
{
par.document.bgColor="#000000"; /* Change the background of the parent window to black */
}
}
</script>
Add the function call in <body onload="checkParent()">  of the child window.
Again, above code is just to change the background color of a parent window. If you want to simulate the behavior of ModalPopupExtender, then you cannot use this approach.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DeMyu
ID: 24092338
It appears that the window.showModalDialog does not meet my requirements. How can I use the ModalPopupExtender such that it pops up a window based on the id passed to it? I have read numerous articles on the ModalPopupExtender but yet to see an example that works for me.

Your assistance is appreciated.

DeMuy
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 24099400
I worte an article on EE to explain how to use AJAX ModalPopupExtender with GridView. It can also be applied to DataList because the principle is the same. http://beta.experts-exchange.com/articles/Programming/Languages/.NET/ASP.NET/Use-AJAX-ModalPopupExtender-in-GridView-or-other-data-controls.html
Let me know if you have any questions on this article and need further help on this question.
0
 

Author Comment

by:DeMyu
ID: 24119025
I am taking a look at your article and trying to implement a solution that is similar to what you have suggested in the article.

Thank you.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question