網頁對話中執行服務器端事件

該例子實現的功能為:用戶申請加入活動,先通過網頁對話登陸,登陸成功后顯示活動詳細信息,用戶提交申請,提交成功返回true,否則返回False.

具體代碼如下:

treeTest.aspx

  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head runat="server">
  3.     <title>Untitled Page</title>
  4.     <script type="text/javascript">
  5.     function Jump()
  6.     {
  7.        var str=window.showModalDialog("Default2.aspx","aaa","dialogHeight:600px;dialogWidth:750px;center:yes;help:no;resizable:no;status:no;");
  8.        alert(str);
  9.     }
  10.     </script>
  11. </head>
  12. <body>
  13.     <form id="form1" runat="server">
  14.     <div id="div1">
  15.         <asp:Button ID="Button1" runat="server" Text="申請加入活動" OnClientClick="return Jump();"/>
  16.         </div>
  17.     </form>
  18. </body>
  19. </html>

 

Default2.aspx

  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head runat="server">
  3.     <title>Untitled Page</title>
  4. </head>
  5. <body>
  6.     <form id="form1" runat="server">
  7.         <iframe src="login.aspx"  style="width:100%;height:100%;">
  8.         </iframe>
  9.     </form>
  10. </body>
  11. </html>

 

login.aspx

  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head runat="server">
  3.     <title>Untitled Page</title>
  4. </head>
  5. <body>
  6.     <form id="form1" runat="server">
  7.     <div>
  8.         <table>
  9.             <tr>
  10.                 <td align="right" style="width: 100px">
  11.                     用戶名:</td>
  12.                 <td style="width: 100px">
  13.                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
  14.                 <td style="width: 100px">
  15.                 </td>
  16.             </tr>
  17.             <tr>
  18.                 <td align="right" style="width: 100px; height: 21px">
  19.                     密碼:</td>
  20.                 <td style="width: 100px; height: 21px">
  21.                     <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
  22.                 <td style="width: 100px; height: 21px">
  23.                 </td>
  24.             </tr>
  25.             <tr>
  26.                 <td align="center" colspan="3" style="height: 21px">
  27.                     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
  28.             </tr>
  29.         </table>
  30.     </div>
  31.     </form>
  32. </body>
  33. </html>
  34. using System;
  35. using System.Data;
  36. using System.Configuration;
  37. using System.Collections;
  38. using System.Web;
  39. using System.Web.Security;
  40. using System.Web.UI;
  41. using System.Web.UI.WebControls;
  42. using System.Web.UI.WebControls.WebParts;
  43. using System.Web.UI.HtmlControls;
  44. public partial class nameSpace08108_login : System.Web.UI.Page
  45. {
  46.     protected void Page_Load(object sender, EventArgs e)
  47.     {
  48.     }
  49.     protected void Button1_Click(object sender, EventArgs e)
  50.     {
  51.         string strName = "aaa" + "|" + "bbb" + "|" + "ccc";
  52.         FormsAuthentication.SetAuthCookie(strName,true);
  53.         Response.Redirect("shengqingxinxi.aspx");
  54.     }
  55. }

 

shengqingxinxi.aspx

  1. <html xmlns="http://www.w3.org/1999/xhtml" >
  2. <head runat="server">
  3.     <title>Untitled Page</title>
  4. </head>
  5. <body>
  6.     <form id="form1" runat="server">
  7.     <div>
  8.         <table>
  9.             <tr>
  10.                 <td align="right" style="width: 100px; height: 23px">
  11.                     用戶名:</td>
  12.                 <td style="width: 100px; height: 23px">
  13.                     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></td>
  14.                 <td style="width: 100px; height: 23px">
  15.                 </td>
  16.             </tr>
  17.             <tr>
  18.                 <td align="right" style="width: 100px; height: 21px">
  19.                     密碼:</td>
  20.                 <td style="width: 100px; height: 21px">
  21.                     <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></td>
  22.                 <td style="width: 100px; height: 21px">
  23.                 </td>
  24.             </tr>
  25.             <tr>
  26.                 <td align="right" style="width: 100px">
  27.                     備注:</td>
  28.                 <td style="width: 100px">
  29.                     <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label></td>
  30.                 <td style="width: 100px">
  31.                 </td>
  32.             </tr>
  33.             <tr>
  34.                 <td align="center" colspan="3">
  35.                     <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/></td>
  36.             </tr>
  37.         </table>
  38.     
  39.     </div>
  40.     </form>
  41. </body>
  42. </html>
  43. using System;
  44. using System.Data;
  45. using System.Configuration;
  46. using System.Collections;
  47. using System.Web;
  48. using System.Web.Security;
  49. using System.Web.UI;
  50. using System.Web.UI.WebControls;
  51. using System.Web.UI.WebControls.WebParts;
  52. using System.Web.UI.HtmlControls;
  53. public partial class nameSpace08108_shengqingxinxi : System.Web.UI.Page
  54. {
  55.     protected void Page_Load(object sender, EventArgs e)
  56.     {
  57.         String[] strUsers = User.Identity.Name.Split('|');
  58.         Label1.Text = strUsers[0];
  59.         Label2.Text = strUsers[1];
  60.         Label3.Text = strUsers[2];
  61.     }
  62.     protected void Button1_Click(object sender, EventArgs e)
  63.     {
  64.         Page.ClientScript.RegisterStartupScript(this.GetType(), "js""<script>window.returnValue=true;window.close();</script>");
  65.     }
  66. }

2008-12-8日補充:最近發現一種更簡潔,更有效的方法來解決此類問題.就是在HTML頭文件中加代碼

<base target="_self"/>.還不清楚這兩種做法有什麽差異,後面清楚了再來補充.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值