Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
XML
<asp:Button ID="Button2" runat="server" Text="Show Custome-Popup" onclick="Button2_Click" />
 <div align ="center" id="popup1" style =" background-color :Fuchsia; width :265px; height :183px; display :none">
 popup message
 </div>

//==================================================Code behind=====
C#
protected void Button2_Click(object sender, EventArgs e)
    {
        string javaScript = "<script language=JavaScript>\n" +
                        "var obj = document.getElementById('popup1');\n" +
                        "obj.style.display = 'block';\n" +
                        "</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "Button2_Click", javaScript);
    }

//============================================================
Pop is displaying perfectly.
But it is displaying below all the other existing controls like textBox, label etc.
How can I display it in the centre of the screen over all other controls.
Posted

increase the z-index of popup1 style="z-index:10000;"

this will bring the popup above all controls.

Change your html as

XML
<div align="center" id="popup1" style="z-index:10000; removed:absolute; background-color :Fuchsia; width :265px; height :183px; display :none;">
 popup message
 </div> 


and change javascript as

Java
document.getElementById("popup1").style.position = "absolute";
document.getElementById("popup1").style.top = "100px";
document.getElementById("popup1").style.left = "100px";
document.getElementById("popup1").style.display = "block";

--Pankaj
 
Share this answer
 
v2
Comments
SHAJANCHERIAN 14-Apr-11 0:40am    
I have included the z-index... But there is no effect..
<div align ="center" id="popup1" style ="z-index:10000; background-color :Fuchsia; width :265px; height :183px; display :none;">
popup message
</div>
any other idea?
pankajupadhyay29 14-Apr-11 0:56am    
ok I got your point below means positionly below i thought in the layer below.
Ok I make the changes for that in solution, hope this will work
pankajupadhyay29 14-Apr-11 0:58am    
I put the top and left hardcoded 100px you can change this by calculating screen height and width and then position for popup
SHAJANCHERIAN 14-Apr-11 1:25am    
Thank U Pankaj..its working Fine.
pankajupadhyay29 14-Apr-11 1:41am    
your welcome if this works for you then mark this as answer
Thank You Pankaj..
Completed code is as follows..
//================in .aspx page=========================
<asp:Button ID="Button2" runat="server" Text="Show Custome-Popup" onclick="Button2_Click" />
XML
<div align ="center"  id="popup1" style ="z-index:10000; background-color :Fuchsia; width :265px; height :183px; display :none;">
 popup message
 </div>

//==============Code Behind======================
XML
protected void Button2_Click(object sender, EventArgs e)
    {
        string javaScript = "<script language=JavaScript>\n" +
                        "var obj = document.getElementById('popup1');\n" +
                        "obj.style.position = 'absolute';\n" +
                        "obj.style.top = '100px'; \n" +
                        "obj.style.left = '500px'; \n" +
                        "obj.style.display = 'block';\n" +
                        "</script>";
        ClientScript.RegisterStartupScript(this.GetType(), "Button2_Click", javaScript);
    }
 
Share this answer
 

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