网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.如何实现Asp与Asp.Net共享Session.
.ASP.NET性能最佳实践 .
.Asp.net url分页的用户控件 .
.在ASP.NET代码里访问跟踪信息.
.跨应用程序进行Forms身份验证详解.
.数据采集程序(网页小偷)点滴心得.
.深入聊聊Array的sort方法的使用技.
.ASP.Net中无法用javascript实现图.
.借助HiddenText 确定CheckBoxLis.
..Net 2.0 原汁原味读取注册表.
.ASP.NET常用的26个优化性能方法.
.asp.net开发wap程序必备:识别来.
.DataGridView 的分页处理.
.为ASP.NET 2.0菜单控件增加targe.
.通过避免下列10个常见ASP.NET缺陷.
.P/Invoke能够在asp.net中使用.
.URL编码处理.
.Asp.net前后台值的调用.
.Asp.net给站点某目录增加Aspnet用.
.用window.location.href实现刷新.

ASP.NET1.0/2.0里用DIV层元素弹出窗体

发表日期:2006-12-5


  本文 Bilal Haidar 将带领您如何使用DIV元素来创建弹出的窗体,这种弹出即可以包含简单的HTML元素也可以包含ASP.NET服务器控件,而且在实现过程中没有使用传统的window函数和showModalDialog / showModelessDialog函数(传统的我们使用 window.open,或者showModalDialog 这样的函数来制作弹出窗口--天天注释)

  最近我在用ASP.NET1.1技术来开发一个窗体,该窗体包含由三个控件组成的一个面板集合,这个面板用来显示系统信息.可以假想这些控件是一些简单的下拉框,当第一个下拉框选取后,第二个下拉框的值将显示被第一个过滤的结果,同样第三个下拉框将根据第二个下拉框的选择而进行改变显示。

  窗体的这个技术通常被用来让终端客户那些不知道ASP.NET技术的人员获取更好的用户体验。

  当决定使用这些控件的替代品使用时,您是否用过dropdownlist或者是具有弹出窗体功能的Textbox控件?

  好了,我们已经有了一个很好的解决方案:使用TextBox控件并挂钩OnClick事件来触发DIV弹出窗体,包括使用Listbox控件来选择数据的值
一个不使用任何常规popup窗体或者过时的Dropdownlist来完成这个功能

   THE HTML WebForm

  我们已经建立了一个简单的WebForm,他包含了一些TextBox,每一个TextBox已经附加了OnClick事件,用一段javascript代码来弹出窗体,代码如下:

<%@ Page language="c#"
Codebehind="ParentPage.aspx.cs" AutoEventWireup="false"
Inherits="PopupWithDiv.ParentPage" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
 <title>Parent Page</title>
 <LINK href="main.css" type="text/css" rel="stylesheet">
 <script src="jsPopup.js" type="text/javascript"></script>
 <script language="javascript">
  <!--
   // Prevent users from typing any text
   // into the Textbox
   function ProtectBox(e)
   {return false; }

  //-->
 </script>
</HEAD>
<body>
 <form id="Form1" method="post" runat="server">
 <!-- Header Section -->
 <div id="header">
  <p>Popup Window with DIV Layer</p>
 </div>
 <!-- Body Section -->
 <div id="content">
  <table border="0" cellpadding="0" cellspacing="0">
  <tr valign="top">
   <td><label for="txtCountry">Country :</label></td>
   <td><asp:TextBox
     id="txtCountry" runat="server" OnKeyDown="return
     ProtectBox(event);" OnClick="PopupArea(event, 'divCountry')"></asp:TextBox></td>
   <td width="50"></td>
   <td><label for="txtCity">City :</label></td>
   <td><asp:TextBox
      id="txtCity" runat="server" OnKeyDown="return
      ProtectBox(event);" OnClick="PopupArea(event, 'divCity')"></asp:TextBox></td>
  </tr>
  </table>
 </div>
 <%-- Country --%>
 <div class="popupWindow" id="divCountry">
  <table cellSpacing="0" cellPadding="0" width="100%" bgColor="#2557ad" border="0">
  <tr>
   <td align="right"><span style="CURSOR: hand"
    onclick="jsAreaClose('divCountry')"><img alt="Hide Popup" src="close.gif"
    border="0"></span></td>
  </tr>
  <tr>
   <td>
    <asp:ListBox id="lstCountry" runat="server" AutoPostBack="True" width="100%"
rows="10"></asp:ListBox></td>
  </tr>
 </table>
 </div>
 <%-- City --%>
  <div class="popupWindow" id="divCity">
  <table
    cellSpacing="0" cellPadding="0" width="100%"
    bgColor="#2557ad" border="0">
  <tr>
   <td align="right"><span style="CURSOR: hand" onclick="jsAreaClose('divCity')"><img alt="Hide Popup" src="close.gif" border="0"></span></td>
  </tr>
  <tr>
   <td>
    <asp:ListBox id="lsCity" runat="server" AutoPostBack="True" width="100%" rows="10"></asp:ListBox>   </td>
  </tr>
  </table>
 </div>
</form>
</body>
</HTML>

  代码中,用粗体标出的部分是Popup窗体的主要属性,在鼠标单击时,将调用一端JavaScript:PopupArea。

  正如您所看到的,我们在页面底部添加了两个DIV元素,一个用于国家,一个用于城市,每一个都包含ListBox控件,用户可以使用Listbox选择上面的内容。

  下图1现实了页面浏览的效果,他还演示了如何弹出DIV窗体


  当单击Textbox内部,windows将弹出窗体而不会引起页面数据回发现在该到填充其中数据的时候了

  Page COde-behind

  在页面后台,我们准备从一个XML文档加载list“国家”所需要的数据,同时显示国家的名称,下面列出了这个功能的代码:

  Listing 2: Populate Country ListBox

// Load data into Country List box
if (!Page.IsPostBack)
{
 // Load data from XML into a DataSet
 DataSet ds = new DataSet();
 ds.ReadXml(Server.MapPath("countries.xml"));

 this.lstCountry.DataSource = ds.Tables[0].DefaultView;
 this.lstCountry.DataTextField = "name";
 this.lstCountry.DataBind();
}

  在这一步骤中,当页面运行时,您可以选择国家,如下图


  现在,当用户选择国家时,将触发listbox的选择事件,并通过该事件加载“城市”数据,该数据同样从XML文档加载

  下面列出了事件代码

  Listing 3

private void lstCountry_SelectedIndexChanged(object sender, EventArgs e)
{
 // Set the value in the textbox
 this.txtCountry.Text = this.lstCountry.SelectedValue;

 // Load and Filter the lstCity
 DataSet ds = new DataSet();
 ds.ReadXml(Server.MapPath("cities.xml"));

 DataView dv = ds.Tables[0].DefaultView;
 dv.RowFilter = "country = '" + this.lstCountry.SelectedValue + "'";

 // Bind lstCity
 this.lstCity.DataSource = dv;
 this.lstCity.DataTextField = "name";
 this.lstCity.DataBind();
}

  用户现在可以选择与国家相匹配的城市,如下

上一篇:脚本获取选中文字及所在句子 人气:4347
下一篇:.NET框架2.0里的aspnet_compiler.exe 人气:4553
浏览全部ASP.NET的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐