該例子實現的功能為:用戶申請加入活動,先通過網頁對話登陸,登陸成功后顯示活動詳細信息,用戶提交申請,提交成功返回true,否則返回False.
具體代碼如下:
treeTest.aspx
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Untitled Page</title>
- <script type="text/javascript">
- function Jump()
- {
- var str=window.showModalDialog("Default2.aspx","aaa","dialogHeight:600px;dialogWidth:750px;center:yes;help:no;resizable:no;status:no;");
- alert(str);
- }
- </script>
- </head>
- <body>
- <form id="form1" runat="server">
- <div id="div1">
- <asp:Button ID="Button1" runat="server" Text="申請加入活動" OnClientClick="return Jump();"/>
- </div>
- </form>
- </body>
- </html>
Default2.aspx
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <iframe src="login.aspx" style="width:100%;height:100%;">
- </iframe>
- </form>
- </body>
- </html>
login.aspx
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td align="right" style="width: 100px">
- 用戶名:</td>
- <td style="width: 100px">
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
- <td style="width: 100px">
- </td>
- </tr>
- <tr>
- <td align="right" style="width: 100px; height: 21px">
- 密碼:</td>
- <td style="width: 100px; height: 21px">
- <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
- <td style="width: 100px; height: 21px">
- </td>
- </tr>
- <tr>
- <td align="center" colspan="3" style="height: 21px">
- <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class nameSpace08108_login : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- string strName = "aaa" + "|" + "bbb" + "|" + "ccc";
- FormsAuthentication.SetAuthCookie(strName,true);
- Response.Redirect("shengqingxinxi.aspx");
- }
- }
shengqingxinxi.aspx
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <table>
- <tr>
- <td align="right" style="width: 100px; height: 23px">
- 用戶名:</td>
- <td style="width: 100px; height: 23px">
- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>
- <td style="width: 100px; height: 23px">
- </td>
- </tr>
- <tr>
- <td align="right" style="width: 100px; height: 21px">
- 密碼:</td>
- <td style="width: 100px; height: 21px">
- <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td>
- <td style="width: 100px; height: 21px">
- </td>
- </tr>
- <tr>
- <td align="right" style="width: 100px">
- 備注:</td>
- <td style="width: 100px">
- <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label></td>
- <td style="width: 100px">
- </td>
- </tr>
- <tr>
- <td align="center" colspan="3">
- <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/></td>
- </tr>
- </table>
- </div>
- </form>
- </body>
- </html>
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class nameSpace08108_shengqingxinxi : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- String[] strUsers = User.Identity.Name.Split('|');
- Label1.Text = strUsers[0];
- Label2.Text = strUsers[1];
- Label3.Text = strUsers[2];
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- Page.ClientScript.RegisterStartupScript(this.GetType(), "js", "<script>window.returnValue=true;window.close();</script>");
- }
- }
2008-12-8日補充:最近發現一種更簡潔,更有效的方法來解決此類問題.就是在HTML頭文件中加代碼
<base target="_self"/>.還不清楚這兩種做法有什麽差異,後面清楚了再來補充.