ASP.NET中MessageBox的实现
asp.net中没有MessageBox这个控件,固然可以插入Winform里的MessageBox,但一般不提倡,所以只能变通实现,主要有这几种方法:
1.直接利用javascript的alert和confirm函数:
在服务端的写法是:
1)alert
ScriptManager.RegisterStartupScript(this, typeof(Page), Guid.NewGuid().ToString(), "alert('Nothing changed.')", true);
2)confirm
将弹出窗口的onclick事件和confirm联系起来:
SaveButton.Attributes.Add("onclick", "return confirm('Are you sure you want to save it?');");
2.利用ajaxToolKit里的ModalPopupExtender和ConfirmButton两个控件:
1)ModalPopupExtender
在aspx文件里的写法:
< ajaxToolkit:ModalPopupExtender runat="server" ID="msgBox" TargetControlID="hiddenTargetControlForModalPopup"
PopupControlID="messageboxPanel" BackgroundCssClass="messagebox_parent" DropShadow="False"
RepositionMode="RepositionOnWindowResizeAndScroll" />
< asp:Button runat="server" ID="hiddenTargetControlForModalPopup" Style="display: none;" />
< asp:Panel runat="server" ID="messageboxPanel" Style="display:none; background-color:white; border: #003399 2px solid; width: 400px; height: 125px;">< div style="text-align:center">Are you sure you want to save it?< /div >< div style="text-align:center" > < asp:Button id="okbutton" runat="server" onclick="okbutton_click" /> < asp:Button id="cancelbutton" runat="server" onclick="cancelbutton_click" />< /asp:Panel>
使用时,在服务端用msgBox.Show()方法来打开,用msgBox.Hide()方法关闭.
2)ConfirmButton
在aspx里:
< %@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
< ajaxToolkit:ConfirmButtonExtender Id="confirmBox" runat="server" ConfirmText="Are your sure you want to save it?" TargetControlID="saveButton" />
saveButton是保存按钮,当用户选择弹出窗口的OK键后就执行它的onclick事件里的语句.
ajaxToolKit本质上是用DIV来模拟弹出窗口.
3.自定义控件:
其实也是利用div来模拟,只不过做得复杂些.下面是一个实例:
ascx:
< %@ Control Langua
相关文档:
首页:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 ......
ASP.NET 应用程序必须位于 IIS 虚拟目录(也称为应用程序根目录)中。ASP.NET 应用程序可包含已编译的程序集(通常是包含业务逻辑的 DLL 文件)、用于存储预编译代码的已知目录(目录名总是 \Bin)、存储在基于文本的、易读的 Web.config 文件中的配置设置、页、服务器控件,以及 XML Web 服务。
服务器中任何不与其他应用 ......
=================================<1>页面控制 ======================================
<script type ="text/javascript" src="../js/Calendar.js"charset ="gb2312"></script>
<input ID="Text1" type="text" runat="server" onfocus="calendar()"/>
<!- ......
法一:调用winrar
using Microsoft.Win32;
using System.Diagnostics;
protected void Button1_Click(object sender, EventArgs e)
{
RAR(@"E:\95413594531\GIS", "tmptest", @"E:\95413594531\");
}
/// < ......
ajax 在目前 web 领域已广泛应用,其真正核心只不过是一个封装好了的 js 库。最五花八门的莫过于 asp.net 的控件,我个人认为 ajax 只是一个轻量级的东西,根本没有必要将它写成服务器组件,如 ajax.net、AjaxControlToolkit 等。所以我一直视这些组件为垃圾。。。
以下说明我为什么不认同 ajax 的相关组件: ......