2015年6月16日 星期二

ASP.NET 子視窗日曆傳值回母視窗控制項上

說明:點選母視窗上的TextBox後,彈出一日曆子視窗,點選日期後回傳至母視窗TextBox上。
--

  1. Parent.aspx
  2. <head runat="server">
  3. <title></title>
  4. <script language="javascript" type="text/javascript">
  5. function SetDate(ClientID)
  6. {
  7. var Url = '../modaldialog/SetDate.aspx?DialogClientID=' + ClientID;
  8. window.open(Url, 'Calendar', 'width=335, height=170');
  9. }
  10. </script>
  11. </head>
  12. <body>
  13. <form id="form1" runat="server">
  14. <asp:TextBox ID="txtDate" runat="server" onclick="SetDate(this.id)"></asp:TextBox>
  15. </form>
  16. </body>
  17. Son.aspx
  18. protected void Calendar1_SelectionChanged(object sender, System.EventArgs e)
  19. {
  20. if (Request.QueryString["DialogClientID"] != null)
  21. {
  22. string strClientID = Request["DialogClientID"].ToString().Trim();
  23. StringBuilder sbJScript = new StringBuilder();
  24. sbJScript.Append("window.opener.document.getElementById('" + strClientID + "').value = '" + this.Calendar1.SelectedDate.ToString("yyyy/MM/dd") + "';");
  25. sbJScript.Append("window.close();");
  26. ClientScript.RegisterStartupScript(this.GetType(), "ReturnValue", sbJScript.ToString(), true);
  27. }
  28. }

沒有留言:

張貼留言