兩種WEB下的模態(tài)對(duì)話框 (asp.net或js的分別實(shí)現(xiàn))
更新時(shí)間:2009年12月02日 01:02:09 作者:
在如今互聯(lián)網(wǎng)網(wǎng)站上,AJAX效果風(fēng)靡一時(shí),應(yīng)該說(shuō)AJAX技術(shù)在未來(lái)幾年不會(huì)動(dòng)搖,在AJAX效果中,模態(tài)對(duì)話框是比較常見(jiàn)的效果,也是非常適用的。
在這里我給大家介紹或者說(shuō)是展示一下我自己的做的兩種模態(tài)對(duì)話框

方法一
本方法是采用ASP.NET AJAX的擴(kuò)展控件:ASP.NET AJAX Control Tool Kit中的ModalPopupExtender控件實(shí)現(xiàn)的:
第一步,我們先創(chuàng)建一個(gè)ASP.NET頁(yè)面:ModalPopup.aspx
頁(yè)面代碼:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxControlToolkit.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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">登陸</asp:LinkButton>
<%--panel的display的CSS屬性必須寫(xiě)在標(biāo)簽里面。--%>
<asp:Panel ID="p_Login" CssClass="p_Login" runat="server" Style="display: none;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p>
用戶名:<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
</p>
<p>
密碼:<asp:TextBox ID="Password" runat="server" CssClass="Password" TextMode="Password"></asp:TextBox>
</p>
<p>
<asp:Button ID="Btn_Submit" runat="server" Text="登錄" OnClick="Btn_Submit_Click" />
<asp:Button ID="Btn_Cancel" runat="server" Text="取消" OnClick="Btn_Cancel_Click" />
</p>
<p>
<asp:Label ID="lbResult" runat="server" Text=""></asp:Label>
<p>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopupExtender1"
PopupControlID="p_Login"
TargetControlID="lbtn_Login"
BackgroundCssClass="ModalPopupBackground"
runat="server">
</cc1:ModalPopupExtender>
</div>
</form>
</body>
</html>
[code]
后臺(tái)代碼:
[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 = "登陸成功!";
}
else
{
this.lbResult.Text = "登錄失敗!";
}
}
protected void Btn_Cancel_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();
this.UserName.Text = "";
this.Password.Text = "";
this.lbResult.Text = "";
}
}
就這樣,通過(guò)很簡(jiǎn)單的擴(kuò)展控件就實(shí)現(xiàn)了模態(tài)對(duì)話框的效果,但是,我后來(lái)想了想,我感覺(jué)用純JS來(lái)實(shí)現(xiàn)更簡(jiǎn)單些,所以,我用純JS來(lái)實(shí)現(xiàn)了一次,很快成功了!
方法二
我們這次創(chuàng)建一個(gè)HTML頁(yè)面:Popup.html
代碼如下:
<!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();">登錄</a>
<div id="loginContent">
<a href="javascript:void(0);" onclick="hideModalPopup();">關(guān)閉</a>
</div>
<div id="hideContent">
</div>
</body>
</html>
就這樣,我用兩種方式實(shí)現(xiàn)了前面展示的那樣的效果,其實(shí)我自己感覺(jué),用純JS寫(xiě)效果比用控件寫(xiě)更好,自己更明確整個(gè)效果代碼的流程。
方法一
本方法是采用ASP.NET AJAX的擴(kuò)展控件:ASP.NET AJAX Control Tool Kit中的ModalPopupExtender控件實(shí)現(xiàn)的:
第一步,我們先創(chuàng)建一個(gè)ASP.NET頁(yè)面:ModalPopup.aspx
頁(yè)面代碼:
復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxControlToolkit.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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">登陸</asp:LinkButton>
<%--panel的display的CSS屬性必須寫(xiě)在標(biāo)簽里面。--%>
<asp:Panel ID="p_Login" CssClass="p_Login" runat="server" Style="display: none;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p>
用戶名:<asp:TextBox ID="UserName" runat="server"></asp:TextBox>
</p>
<p>
密碼:<asp:TextBox ID="Password" runat="server" CssClass="Password" TextMode="Password"></asp:TextBox>
</p>
<p>
<asp:Button ID="Btn_Submit" runat="server" Text="登錄" OnClick="Btn_Submit_Click" />
<asp:Button ID="Btn_Cancel" runat="server" Text="取消" OnClick="Btn_Cancel_Click" />
</p>
<p>
<asp:Label ID="lbResult" runat="server" Text=""></asp:Label>
<p>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
<cc1:ModalPopupExtender ID="ModalPopupExtender1"
PopupControlID="p_Login"
TargetControlID="lbtn_Login"
BackgroundCssClass="ModalPopupBackground"
runat="server">
</cc1:ModalPopupExtender>
</div>
</form>
</body>
</html>
[code]
后臺(tái)代碼:
[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 = "登陸成功!";
}
else
{
this.lbResult.Text = "登錄失敗!";
}
}
protected void Btn_Cancel_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();
this.UserName.Text = "";
this.Password.Text = "";
this.lbResult.Text = "";
}
}
就這樣,通過(guò)很簡(jiǎn)單的擴(kuò)展控件就實(shí)現(xiàn)了模態(tài)對(duì)話框的效果,但是,我后來(lái)想了想,我感覺(jué)用純JS來(lái)實(shí)現(xiàn)更簡(jiǎn)單些,所以,我用純JS來(lái)實(shí)現(xiàn)了一次,很快成功了!
方法二
我們這次創(chuàng)建一個(gè)HTML頁(yè)面:Popup.html
代碼如下:
復(fù)制代碼 代碼如下:
<!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();">登錄</a>
<div id="loginContent">
<a href="javascript:void(0);" onclick="hideModalPopup();">關(guān)閉</a>
</div>
<div id="hideContent">
</div>
</body>
</html>
就這樣,我用兩種方式實(shí)現(xiàn)了前面展示的那樣的效果,其實(shí)我自己感覺(jué),用純JS寫(xiě)效果比用控件寫(xiě)更好,自己更明確整個(gè)效果代碼的流程。
您可能感興趣的文章:
- JS 模態(tài)對(duì)話框和非模態(tài)對(duì)話框操作技巧匯總
- 利用javascript打開(kāi)模態(tài)對(duì)話框(示例代碼)
- javascript showModalDialog模態(tài)對(duì)話框使用說(shuō)明
- JavaScript 實(shí)現(xiàn)模態(tài)對(duì)話框 源代碼大全
- 詳解AngularJS 模態(tài)對(duì)話框
- JS對(duì)話框_JS模態(tài)對(duì)話框showModalDialog用法總結(jié)
- js模態(tài)對(duì)話框使用方法詳解
- js實(shí)現(xiàn)div模擬模態(tài)對(duì)話框展現(xiàn)URL內(nèi)容
- ModelDialog JavaScript模態(tài)對(duì)話框類代碼
- JavaScript實(shí)現(xiàn)模態(tài)對(duì)話框?qū)嵗?/a>
- js實(shí)現(xiàn)響應(yīng)按鈕點(diǎn)擊彈出可拖拽的非模態(tài)對(duì)話框完整實(shí)例【測(cè)試可用】
相關(guān)文章
mui 打開(kāi)新窗口的方式總結(jié)及注意事項(xiàng)
這篇文章主要介紹了mui 打開(kāi)新窗口的方式總結(jié)及注意事項(xiàng),需要的朋友可以參考下2017-08-08javascript游戲開(kāi)發(fā)之《三國(guó)志曹操傳》零部件開(kāi)發(fā)(四)用地圖塊拼成大地圖
小時(shí)候我們玩過(guò)拼圖游戲,是用自己的手去拼的。今天我們來(lái)研究研究用javascript來(lái)拼圖感興趣的朋友可以了解下,希望本文對(duì)你有所幫助2013-01-01webpack打包時(shí)如何修改文件名的實(shí)現(xiàn)示例
本文主要介紹了webpack打包時(shí)如何修改文件名的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06js canvas實(shí)現(xiàn)5張圖片合成一張圖片
這篇文章主要為大家詳細(xì)介紹了js canvas實(shí)現(xiàn)5張圖片合成一張圖片,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07