ASP.Net WebForm實作Open Dialog視窗互動

ASP.Net WebForm實作Open Dialog視窗互動

aspx

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourNamespace.Default" %>
  2. <!DOCTYPE html>
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5. <title>彈跳視窗範例</title>
  6. <style>
  7. #popup {
  8. display: none;
  9. position: fixed;
  10. top: 50%;
  11. left: 50%;
  12. transform: translate(-50%, -50%);
  13. border: 1px solid #ccc;
  14. background-color: #fff;
  15. padding: 20px;
  16. z-index: 1000;
  17. width: 300px; /* 調整寬度 */
  18. }
  19. #popupTitle {
  20. font-size: 18px;
  21. font-weight: bold;
  22. margin-bottom: 10px;
  23. }
  24. #popupContent {
  25. margin-bottom: 20px;
  26. }
  27. #popupButtons {
  28. text-align: right;
  29. }
  30. #popupButtons button {
  31. margin-left: 10px;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. <form id="form1" runat="server">
  37. <asp:ScriptManager runat="server"></asp:ScriptManager>
  38. <div>
  39. <!-- 主要內容區域 -->
  40. <asp:Panel ID="MainContent" runat="server">
  41. <asp:Button ID="btnShowPopup" runat="server" Text="顯示彈跳視窗" OnClientClick="showPopup(); return false;" />
  42. </asp:Panel>
  43. <!-- 彈跳視窗 -->
  44. <div id="popup">
  45. <div id="popupTitle">彈跳視窗標題</div>
  46. <div id="popupContent">
  47. <asp:Label ID="lblMessage" runat="server" Text="確定要執行此操作嗎?"></asp:Label>
  48. </div>
  49. <div id="popupButtons">
  50. <asp:Button ID="btnOK" runat="server" Text="確定" OnClick="btnOK_Click" />
  51. <asp:Button ID="btnCancel" runat="server" Text="取消" OnClientClick="hidePopup(); return false;" />
  52. </div>
  53. </div>
  54. </div>
  55. <!-- 在這裡加入其他內容或控制項 -->
  56. </form>
  57. <script type="text/javascript">
  58. function showPopup() {
  59. document.getElementById('popup').style.display = 'block';
  60. }
  61. function hidePopup() {
  62. document.getElementById('popup').style.display = 'none';
  63. }
  64. </script>
  65. </body>
  66. </html>

aspx.cs

  1. using System;
  2. using System.Web.UI;
  3. namespace YourNamespace
  4. {
  5. public partial class Default : Page
  6. {
  7. protected void Page_Load(object sender, EventArgs e)
  8. {
  9. // 此處可以加入其他初始化邏輯
  10. }
  11. protected void btnOK_Click(object sender, EventArgs e)
  12. {
  13. // 在畫面上的textbox1顯示"OK"
  14. TextBox textbox1 = (TextBox)MainContent.FindControl("textbox1");
  15. if (textbox1 != null)
  16. {
  17. textbox1.Text = "OK";
  18. }
  19. // 關閉彈跳視窗
  20. ScriptManager.RegisterStartupScript(this, GetType(), "hidePopup", "hidePopup();", true);
  21. }
  22. }
  23. }

上述程式碼中,我們使用了ASP.NET的Panel控制項來包裝主要內容區域,並使用CSS和JavaScript來實現彈跳視窗的樣式和顯示/隱藏效果。在彈跳視窗中,我們有兩個按鈕(OK和Cancel),並在btnOK_Click事件中處理按下OK按鈕的邏輯。在JavaScript中的showPopup和hidePopup函數用於顯示和隱藏彈跳視窗。請注意,這只是一個基本的範例,實際應用可能需要根據您的需求進行調整。

留言

這個網誌中的熱門文章

ORA-12514: TNS: 監聽器目前不知道連線描述區中要求的服務

Oracle 工作排程 DBMS_JOB 筆記

Oracle 例外控制(Exception Control)