All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
将SSH与PHP相连接 确保传输数据的安全_[PHP教程]
Asp.net,备份和还原SQL,Server及压缩Access数据库_[Asp.Net教程]
用,PHPRPC,实现,Ajax,级联下拉菜单_php资料_编程技术
Spring集成XFire开发WebService_.net资料_编程技术
PHP截取UTF-8字符串,解决半字符问题_[PHP教程]
应用技巧:用PHP简易实现中文分词_php资料_编程技术
HTML 初学者指南_[Html教程]
ASP.NET3.5的ListView与CSS,Friendly_.net资料_编程技术
怎么将现有的网站过渡到XHTML_[Html教程]
以xml数据源作无限级联动下拉框_[Asp.Net教程]
Reading number is top 10 pictures
Hunan province aizhai super-large suspension bridge open to traffic and 4 world first2
The real super beauty12
BingBingFan apple dew point photo gallery3
初五接财神啦!五路财神齐来到
Embarrassing things comic collection2
YangYuYing and ZhengShaoQiu dance on the generous come interest dye-in-the-wood
NeedWallpaper9
Female star bikini
NeedWallpaper14
采访美女孙菲菲
Download software ranking
美女游泳记
双旗镇刀客A
美女写真3
Unix video tutorial2
传奇私服架设教程
I'm come from Beijing1
Eclipse 4.2.2 For Win64
Call Of Duty5
Unix video tutorial10
都市狐狸姑娘传
aaa published in(发表于) 2013/12/13 9:12:36 Edit(编辑)
2.0里用DIV层元素弹出窗体_.net资料_编程技术

2.0里用DIV层元素弹出窗体_.net资料_编程技术

ASP.NET1.0/2.0里用DIV层元素弹出窗体_.net资料_编程技术-你的首页-uuhomepage.com
  本文 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="" 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="" 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();
}

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








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.