Here I will introduce you or show you the two modal dialogs I have made.
Method 1
This method is implemented using the extension control of ASP. NET Ajax: modalpopupextender control in ASP. NET Ajax control tool kit:
Step 1: Create an ASP. NET page: modalpopup. aspx
Page Code :
Copy code The Code is as follows: <% @ page Language = "C #" autoeventwireup = "true" codefile = "ajaxcontroltoolkit. aspx. cs"
Inherits = "_ default" %>
<% @ Register Assembly = "ajaxcontroltoolkit" namespace = "ajaxcontroltoolkit" tagprefix = "PC3" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> </title>
<Style type = "text/CSS">
. P_login
{}{
Width: 230px;
Height: 180px;
Padding: 15px 15px 15px 15px;
Background-color: # FFF;
Border: 2px solid # CCC;
}
. Password
{}{
Margin-left: 15px;
}
. Modalpopupbackground
{}{
Background-color: # dddddd;
Filter: alpha (opacity = 60);/** // * ie */
Opacity: 60;/** // * Firefox */
}
</Style>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: scriptmanager id = "scriptmanager1" runat = "server">
</ASP: scriptmanager>
<Asp: linkbutton id = "lbtn_login" runat = "server"> login </ASP: linkbutton>
<% -- The CSS attribute of panel display must be written in the tag. -- %>
<Asp: Panel id = "p_login" cssclass = "p_login" runat = "server" style = "display: none;">
<Asp: updatepanel id = "updatepanel1" runat = "server">
<Contenttemplate>
<P>
Username: <asp: textbox id = "username" runat = "server"> </ASP: textbox>
</P>
<P>
Password: <asp: textbox id = "password" runat = "server" cssclass = "password" textmode = "password"> </ASP: textbox>
</P>
<P>
<Asp: button id = "btn_submit" runat = "server" text = "login" onclick = "btn_submit_click"/>
<Asp: button id = "btn_cancel" runat = "server" text = "cancel" onclick = "btn_cancel_click"/>
</P>
<P>
<Asp: Label id = "lbresult" runat = "server" text = ""> </ASP: Label>
<P>
</Contenttemplate>
</ASP: updatepanel>
</ASP: Panel>
<PC3: modalpopupextender id = "modalpopupextender1"
Popupcontrolid = "p_login"
Targetcontrolid = "lbtn_login"
Backgroundcssclass = "modalpopupbackground"
Runat = "server">
</PC3: modalpopupextender>
</Div>
</Form>
</Body>
</Html>
[Code]
Background code:
[Code]
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
}
Protected void btn_submit_click (Object sender, eventargs E)
{
If (this. username. Text. Trim (). toupper () = "Jacky" & this. Password. Text. Trim () = "123 ")
{
This. lbresult. Text = "Login successful! ";
}
Else
{
This. lbresult. Text = "Logon Failed! ";
}
}
Protected void btn_cancel_click (Object sender, eventargs E)
{
This. modalpopupextender1.hide ();
This. username. Text = "";
This. Password. Text = "";
This. lbresult. Text = "";
}
}
In this way, the modal dialog box effect is achieved through a simple extension control. However, I thought about it later, and I felt it easier to implement it using pure Js, I implemented it once with pure JS and soon succeeded!
Method 2
This time we create an HTML page: popup.html
The Code is as follows: Copy code The Code is as follows: <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Style type = "text/CSS">
# Logincontent
{}{
Position: absolute;
Left: 40%;
Top: 30%;
Width: 230px;
Height: 180px;
Padding: 15px 15px 15px 15px;
Background-color: # FFF;
Border: 2px solid # CCC;
Background-color: # FFF;
Z-index: 100;
Display: none;
}
# Hidecontent
{}{
Display: none;
Position: absolute;
Top: 0;
Left: 0;
Height: 100%;
Width: 100%;
Z-index: 50;
Background-color: # dddddd;
Filter: alpha (opacity = 60);/** // * ie */opacity: 60;/** // * Firefox */
}
</Style>
<SCRIPT type = "text/JavaScript">
VaR hidecontent = Document. getelementbyid ("hidecontent ");
VaR logincontent = Document. getelementbyid ("logincontent ");
Function showmodalpopup (){
Hidecontent. style. Display = "Block ";
Logincontent. style. Display = "Block ";
}
Function hidemodalpopup (){
Hidecontent. style. Display = "NONE ";
Logincontent. style. Display = "NONE ";
}
</SCRIPT>
<Title> </title>
</Head>
<Body>
<A href = "javascript: void (0);" onclick = "showmodalpopup ();"> log on </a>
<Div id = "logincontent">
<A href = "javascript: void (0);" onclick = "hidemodalpopup ();"> disable </a>
</Div>
<Div id = "hidecontent">
</Div>
</Body>
</Html>
in this way, I used two methods to achieve the effect shown above. In fact, I feel that it is better to use pure js to write results than to use controls, clearly define the entire effect code process.