|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你觉得数据库怎么样?asp.net 本文BilalHaidar将率领您怎样利用DIV元从来创立弹出的窗体,这类弹出便可以包括复杂的HTML元素也能够包括ASP.NET服务器控件,并且在完成过程当中没有利用传统的window函数和showModalDialog/showModelessDialog函数(传统的我们利用window.open,大概showModalDialog如许的函数来制造弹出窗口--每天正文)
比来我在用ASP.NET1.1手艺来开辟一个窗体,该窗体包括由三个控件构成的一个面板汇合,这个面板用来显现体系信息.能够设想这些控件是一些复杂的下拉框,当第一个下拉框拔取后,第二个下拉框的值将显现被第一个过滤的了局,一样第三个下拉框将依据第二个下拉框的选择而举行改动显现。
窗体的这个手艺一般被用来让终端客户那些不晓得ASP.NET手艺的职员猎取更好的用户体验。
当决意利用这些控件的替换品利用时,您是不是用过dropdownlist大概是具有弹出窗体功效的Textbox控件?
好了,我们已有了一个很好的办理计划:利用TextBox控件并挂钩OnClick事务来触发DIV弹出窗体,包含利用Listbox控件来选择数据的值
一个不利用任何惯例popup窗体大概过期的Dropdownlist来完成这个功效
THEHTMLWebForm
我们已创建了一个复杂的WebForm,他包括了一些TextBox,每个TextBox已附加了OnClick事务,用一段javascript代码来弹出窗体,代码以下:
<%@Pagelanguage="c#"
Codebehind="ParentPage.aspx.cs"AutoEventWireup="false"
Inherits="PopupWithDiv.ParentPage"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<HTML>
<HEAD>
<title>ParentPage</title>
<LINKhref="main.CSS"type="text/css"rel="stylesheet">
<scriptsrc="jsPopup.js"type="text/javascript"></script>
<scriptlanguage="javascript">
<!--
//Preventusersfromtypinganytext
//intotheTextbox
functionProtectBox(e)
{returnfalse;}
//-->
</script>
</HEAD>
<body>
<formid="Form1"method="post"runat="server">
<!--HeaderSection-->
<divid="header">
<p>PopupWindowwithDIVLayer</p>
</div>
<!--BodySection-->
<divid="content">
<tableborder="0"cellpadding="0"cellspacing="0">
<trvalign="top">
<td><labelfor="txtCountry">Country:</label></td>
<td><asp:TextBox
id="txtCountry"runat="server"></asp:TextBox></td>
<tdwidth="50"></td>
<td><labelfor="txtCity">City:</label></td>
<td><asp:TextBox
id="txtCity"runat="server"></asp:TextBox></td>
</tr>
</table>
</div>
<%--Country--%>
<divclass="popupWindow"id="divCountry">
<tablecellSpacing="0"cellPadding="0"width="100%" bgColor="#2557ad"border="0">
<tr>
<tdalign="right"><spanstyle="CURSOR:hand"
><imgalt="HidePopup"src="http://www.webjx.com/htmldata/2006-12-05/close.gif"
border="0"></span></td>
</tr>
<tr>
<td>
<asp:ListBoxid="lstCountry"runat="server"AutoPostBack="True"width="100%"
rows="10"></asp:ListBox></td>
</tr>
</table>
</div>
<%--City--%>
<divclass="popupWindow"id="divCity">
<table
cellSpacing="0"cellPadding="0"width="100%"
bgColor="#2557ad"border="0">
<tr>
<tdalign="right"><spanstyle="CURSOR:hand"><imgalt="HidePopup"src="http://www.webjx.com/htmldata/2006-12-05/close.gif"border="0"></span></td>
</tr>
<tr>
<td>
<asp:ListBoxid="lsCity"runat="server"AutoPostBack="True"width="100%"rows="10"></asp:ListBox> </td>
</tr>
</table>
</div>
</form>
</body>
</HTML>
代码中,用粗体标出的部分是Popup窗体的次要属性,在鼠标单击时,将挪用一端JavaScript:PopupArea。
正如您所看到的,我们在页面底部增加了两个DIV元素,一个用于国度,一个用于乡村,每个都包括ListBox控件,用户可使用Listbox选择下面的内容。
下实际了页面扫瞄的效果,他还演示了怎样弹出DIV窗体
当单击Textbox外部,windows将弹出窗体而不会引发页面数据回发明在该到添补个中数据的时分了
<P> PageCOde-behind
在页面背景,我们筹办从一个XML文档加载list“国度”所必要的数据,同时显现国度的称号,上面列出了这个功效的代码:
Listing2:PopulateCountryListBox
//LoaddataintoCountryListbox
if(!Page.IsPostBack)
{
//LoaddatafromXMLintoaDataSet
DataSetds=newDataSet();
ds.ReadXml(Server.MapPath("countries.xml"));
this.lstCountry.DataSource=ds.Tables[0].DefaultView;
this.lstCountry.DataTextField="name";
this.lstCountry.DataBind();
}
在这一步骤中,当页面运转时,您能够选择国度,以下图
如今,当用户选择国度时,将触发listbox的选择事务,并经由过程该事务加载“乡村”数据,该数据一样从XML文档加载
上面列出了事务代码
Listing3
privatevoidlstCountry_SelectedIndexChanged(objectsender,EventArgse)
{
//Setthevalueinthetextbox
this.txtCountry.Text=this.lstCountry.SelectedValue;
//LoadandFilterthelstCity
DataSetds=newDataSet();
ds.ReadXml(Server.MapPath("cities.xml"));
DataViewdv=ds.Tables[0].DefaultView;
dv.RowFilter="country="+this.lstCountry.SelectedValue+"";
//BindlstCity
this.lstCity.DataSource=dv;
this.lstCity.DataTextField="name";
this.lstCity.DataBind();
}
用户如今能够选择与国度相婚配的乡村,以下
就安全性而言,Java已经远远低于VB.NET,更无法与安全性著称的C#相比。 |
|