初学asp.net,学作了一个模拟对话框效果的例子,
在主页面上有一个TextBox和一个按钮,点击按钮弹出一个模态显示的页面
,输入文本后点击OK回到主页面,并传回文本值。
很简单的东东,让大家见笑了
主页面:
<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
btnOpen.Attributes.Add("onclick", @"var strReturn; strReturn=window.showModalDialog('DialogForm.aspx',null,'status:no;dialogWidth:250px;dialogHeight:125px;dialogHide:true;help:no;scroll:no');if (strReturn != null) document.getElementById('txtValue').value=strReturn;");
}
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtValue" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:Button id="btnOpen" style="Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 24px" runat="server" Text="Open"></asp:Button>
</form>
</body>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
btnOpen.Attributes.Add("onclick", @"var strReturn; strReturn=window.showModalDialog('DialogForm.aspx',null,'status:no;dialogWidth:250px;dialogHeight:125px;dialogHide:true;help:no;scroll:no');if (strReturn != null) document.getElementById('txtValue').value=strReturn;");
}
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtValue" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:Button id="btnOpen" style="Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 24px" runat="server" Text="Open"></asp:Button>
</form>
</body>
对话框页面:
<%@ Page Language="C#" %>
<script runat="server">
private void Page_Load( object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
btnOK.Attributes.Add("onclick", @"window.returnValue = document.getElementById('txtValue').value; window.close();");
btnCancel.Attributes.Add("onclick", @"window.close();");
}
}
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtValue" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:Button id="btnOK" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 56px" runat="server" Text="Ok" Width="56px"></asp:Button>
<asp:Button id="btnCancel" style="Z-INDEX: 102; LEFT: 112px; POSITION: absolute; TOP: 56px" runat="server" Text="Cancel"></asp:Button>
</form>
</body>
<script runat="server">
private void Page_Load( object sender, System.EventArgs e)
{
if ( !IsPostBack )
{
btnOK.Attributes.Add("onclick", @"window.returnValue = document.getElementById('txtValue').value; window.close();");
btnCancel.Attributes.Add("onclick", @"window.close();");
}
}
</script>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:TextBox id="txtValue" style="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 24px" runat="server"></asp:TextBox>
<asp:Button id="btnOK" style="Z-INDEX: 103; LEFT: 48px; POSITION: absolute; TOP: 56px" runat="server" Text="Ok" Width="56px"></asp:Button>
<asp:Button id="btnCancel" style="Z-INDEX: 102; LEFT: 112px; POSITION: absolute; TOP: 56px" runat="server" Text="Cancel"></asp:Button>
</form>
</body>