Analytics

2010年6月30日 星期三

[ASP.NET]使用Javascript關閉視窗(C # uses Javascript Close Window)


問題
使用Javascript關閉視窗



解決方法
要做到關閉視窗,目前得借助Javascript的幫忙!
語法如下:
  1. Response.Write ("<script language='javascript'>window.close();</script>");

2010年6月25日 星期五

[ASP.NET]以變數動態變更圖檔目錄以實現多國語系方法(Drawing with variable dynamic change directory to enable multiple language method)


問題

以變數動態變更圖檔目錄以實現多國語系方法



解決方法

架構如下:
以session紀錄"語系"變數,並在postback時觸發變更路徑的function以實現此目的

.aspx程式碼:
  1. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head >
  5. </head>
  6. <body>
  7.     <form id="form1" runat="server">
  8.         &nbsp;<asp:LinkButton ID="btnzh" runat="server" OnClick="btnzh_Click">繁中</asp:LinkButton>/<asp:LinkButton
  9.             ID="btncn" runat="server" OnClick="btncn_Click">簡中</asp:LinkButton>/<asp:LinkButton
  10.                 ID="btnen" runat="server" OnClick="btnen_Click">English</asp:LinkButton>
  11.         <br />
  12.         <br />
  13.             <img src="./<%=myver%>/cccq1.jpg" /><br />
  14.     </form>
  15. </body>
  16. </html>
  17.  
.cs程式碼:
  1. namespace WebApplication1
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.         protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.             Session["ver"] = "zh";
  8.             GetPath();
  9.         }
  10.         /// <summary>
  11.         /// 取得圖檔路徑
  12.         /// </summary>
  13.         public void GetPath()
  14.         {
  15.             string _path = "img_";
  16.             myver= _path + Convert.ToString(Session["ver"]);
  17.         }
  18.         public string myver = "";
  19.         protected void btnzh_Click(object sender, EventArgs e)
  20.         {
  21.             Session["ver"] = "zh";
  22.             GetPath();
  23.         }
  24.         protected void btncn_Click(object sender, EventArgs e)
  25.         {
  26.             Session["ver"] = "cn";
  27.             GetPath();
  28.         }
  29.         protected void btnen_Click(object sender, EventArgs e)
  30.         {
  31.             Session["ver"] = "en";
  32.             GetPath();
  33.         }
  34.     }
  35. }

2010年6月21日 星期一

[ASP.NET]如何 取ViewState裡的值(Take the ViewState value)


問題

如何 取ViewState裡的值

在C#裡,DataTable轉型用類似下列語法:
  1. DataTable dt = new DataTable();
  2. //隱含轉型
  3. dt=(DataTable)ViewState("test");
但是在VB.NET裡面
這樣使用的時候,將會得到"'DataTable' 為型別,無法當成運算式使用。   "的錯誤


解決方法

Dim dt As New DataTable  
  1. dt = DirectCast(ViewState("test"), DataTable)
這樣就可以取出ViewState裡的Table了

2010年6月18日 星期五

[VISUAL STUDIO]執行階段錯誤: '/LM/W3SVC/1/ROOT/' 不是有效的 IIS 應用程式。(ASP.NET implementation phase error: '/ LM / W3SVC / 1 / ROOT /' is not a valid IIS application.)


問題

執行階段錯誤: '/LM/W3SVC/1/ROOT/' 不是有效的 IIS 應用程式。(ASP.NET implementation phase error: '/ LM / W3SVC / 1 / ROOT /' is not a valid IIS application.)

今天在修改程式的時候,發現了這個錯誤!.aspx裡面的控制項顯示標題的錯誤"ASP.NET 執行階段錯誤: '/LM/W3SVC/1/ROOT/' 不是有效的 IIS 應用程式。"
但是原先專案之前執行的時候,都是正常的~

解決方法

1.檢查"'方案總管"=>"屬性頁籤"
2.底下=>"Web頁籤"=>檢查"伺服器"底下的選項是否為"使用Visual Studio程式開發伺服器"
3.若不是,則選擇,存檔後記得要再"建置"一次應用程式,否則檢視設計畫面一樣不會變動歐!!建置後就會正常了!!

出現此錯誤原因,在於伺服器選項使用"IIS Web 伺服器",而該底下的網址又並未在IIS底下建立,因此才會造成!!

2010年6月15日 星期二

[Javascript]下拉式選單連動(Dropdown linked)


問題

下拉式選單連動



解決方法

資料來源:javaworld
  1. <html>
  2.   <script>
  3.     // 通常,當資料選項的變動性不大時,都會直接寫成 .js 檔含入即可。
  4.     var country = new Array();          
  1. // 看幾個國家     
  1. country[0] = '台灣';     
  1. country[1] = '中國';     
  1. country[2] = '日本';     
  1. var city = new Array();
  2.     city[0] = new Array();    
  1. // 台灣的城市
  2.     city[0][0] = '台北';     
  1. city[0][1] = '台中';     
  1. city[0][2] = '台南';     
  1. city[0][3] = '高雄';     
  1. city[1] = new Array();    
  1. // 中國的城市     
  1. city[1][0] = '北京';     
  1. city[1][1] = '上海';     
  1. city[1][2] = '南京';     
  1. city[2] = new Array();    
  1. // 日本的城市     
  1. city[2][0] = '東京';     
  1. city[2][1] = '名古屋';     
  1. // 載入 master 選單,同時初始化 detail 選單內容
  2.     function loadMaster( master, detail ) 
  1. {
  2.       master.options.length = country.length;
  3.       for( i = 0; i < country.length; i++ ) 
  1. {
  2.         master.options[ i ] = new Option( country[i], country[i] );  
  1. // Option( text , value );
  2.       }
  3.       master.selectedIndex = 0;
  4.       doNewMaster( master, detail );
  5.     }
  6.     // 當 master 選單異動時,變更 detail 選單內容
  7.     function doNewMaster( master, detail ) {
  8.       detail.options.length = city[ master.selectedIndex ].length;
  9.       for( i = 0; i < city[ master.selectedIndex ].length; i++ ) 
  1. {
  2.         detail.options[ i ] = new Option( city[ master.selectedIndex ][ i ],
  3.                                           city[ master.selectedIndex ][ i ] );
  4.       }
  5.     }
  6.   </script>
  7.   <body onload="loadMaster( document.getElementById( 'country' ), document.getElementById( 'city' ) );">
  8.     <select name="country" id="country"
  9.         onChange="doNewMaster( document.getElementById( 'country' ),document.getElementById( 'city' ) );">
  10.    </select>
  11.    <select name="city" id="city">
  12.    </select>
  13.    </body>
  14. </html>
  15.  

2010年6月11日 星期五

[Javascript]配合onclientclick屬性呼叫confirm()判斷是否要繼續執行(Are property with onclientclick call confirm () is determined to continue)


問題

配合onclientclick屬性呼叫confirm()判斷是否要繼續執行



解決方法

程式流程如下:
按下確定按鈕->檢查RadioButtonList的選項,若為0則某欄位不得為空白,否則顯示"該必填欄位空白,確定繼續?!"->若"是"則繼續傳回Server端執行,若"否",則停在該頁面
程式碼片段如下:
  1. function CheckVaild()
  2. {
  3. var table;         //取得RadioButtonList    
  4. table=document.getElementById("RadioButtonList1");
  5. for(i=0;i<table.rows[0].cells.length;i++)
  6. {
  7. if(table.rows[0].cells[i].childNodes[0].checked == true)
  8. {
  9. selValue = table.rows[0].cells[i].childNodes[0].value;  
  10. break;
  11. }
  12. //RadioButtonList=0,且必填欄位空白,跳出確認視窗
  13. if (selValue=="0")
  14. {
  15. if (document.getElementById("TxtBox1").value=="")
  16. {
  17. var r=confirm("該必填欄位空白,確定繼續?!");
  18. if (r==true)
  19. {}
  20. else
  21. {
  22. var mytext = document.getElementById("TxtBox1");
  23. mytext.focus();
  24. window.event.returnValue=false;
  25. }
  26. }
  27. }
  28. }
  29. }
  30.  
  31.  
  32.  
  1. <asp:button id="btnSave" runat="server" Text="確定" OnClientClick="return CheckVaild();"></asp:button>

2010年6月10日 星期四

進銷存系統開發實務-SystemDesign

TableLayout
  • 進貨資料表
進貨紀錄表 OrderHirstory    
中文名稱 欄位名稱 型態 說明
產品名稱 ProductName string  
進貨數量 Quantity int  
進貨價格 Price decimal  
建立日期 CreateDate datetime 建單日期
建立者 CreateID string 建單人員ID
確認日期 ConfirmDate datetime 確認到貨日期
確認者 ConfirmID string 確認人員ID
鍵值 OrderID int 每筆資料加1

庫存表 OrderStock    
中文名稱 欄位名稱 型態 說明
產品名稱 ProductName string  
數量 Quantity int 進貨時寫入;
若有同產品:則把原資料加上進貨數量
若無:寫進貨數量
進貨更新日期 UpdateDate datetime 即進貨日期
進貨更新者 UpdateID string 即進貨人員ID
  • 出貨資料表
出貨表 OrderForm    
中文名稱 欄位名稱 型態 說明
客戶名稱 CusID string 由客戶資料表取得ID,
若無此客戶,
則新增此客戶再寫回
產品名稱 ProductName string  
訂購數量 Quantity int  
銷售價格 Price decimal  
應付金額 TotalPrice decimal 出貨對象
0:0
非0:訂購數量*銷售價格
出貨對象 Object int 0:VIP(樣品或贈品,應付金額為0)
1:一般客戶
2:店家
3:經銷商
付款方式 PayType int 0:現金
1:支票
已收金額 RecivePrice int  
支票號碼 CheckNo string 付款方式
0:空白
1:且支票狀態2時才可輸入
票期 CheckRange int 付款方式
0:0
1:必填
支票狀態 CheckStatus int 0:付款方式0寫0
1:未收票
2:已收票/未入帳
3:已入帳
支票狀態日1 CheckDate1 string 付款方式為1:
且支票狀態為1時寫入日期
支票狀態日2 CheckDate2 string 付款方式為1
且支票狀態為2時寫入日期
支票狀態日3 CheckDate3 string 付款方式為1
且支票狀態為3時寫入日期
建立日期 CreateDate datetime 建單日期
建立者 CreateID string 建單人員ID
確認日期 ConfirmDate datetime 確認到貨日期
確認者 ConfirmID string 確認人員ID
鍵值 OrderNo int 每筆資料自動加1
  • 退貨資料表
退貨表 OrderReturns    
中文名稱 欄位名稱 型態 說明
訂單編號 OrderNo int 從出貨單帶入
退貨方式 ReturnType int 0:退貨
1:換貨
客戶名稱 CusID string 出貨單帶入
(唯讀)
產品名稱 ProductName string 出貨單帶入
(唯讀)
退貨數量 Quantity int 若出貨對象
0:唯讀
非0則開放輸入
銷售價格 Price decimal 出貨單帶入
(唯讀)
應退金額 TotalPrice decimal 出貨對象
0:0
非0:退貨數量*銷售價格
退款方式 ReturnType int 0:現金
1:支票
開票號碼 ReturnCheck string 退款方式
0:空白
1:若支票狀態1,則可保留空白;2,則可保留空白;3則必key號碼
出貨對象 Object int 0:VIP 
1:一般客戶
2:店家
3:經銷商
出貨單帶入
為0:退貨方式固定為換貨
付款方式 PayType int 0:現金
1:支票
支票號碼 CheckNo string 出貨單帶入
支票狀態 CheckStatus int 出貨單帶入
支票狀態日1 CheckDate1 string 出貨單帶入
支票狀態日2 CheckDate2 string 出貨單帶入
支票狀態日3 CheckDate3 string 出貨單帶入
建立日期 CreateDate datetime 建單日期
建立者 CreateID string 建單人員ID
確認日期 ConfirmDate datetime 確認到貨日期
確認者 ConfirmID string 確認人員ID
鍵值 OrderNo int 每筆資料動加1

進銷存系統開發實務-SystemAnalysis

此進銷存系統提供公司進貨,出貨,退貨紀錄,以及檢視營業額,盤點庫存的功能

  • 進貨流程

KEY IN 進貨單->列印進貨單及付款->確認收到進貨品項無誤->入庫存與新增進貨紀錄

  • 出貨流程

KEY IN 出貨單->列印出貨單及整貨待出->確認貨品以經交付到客人手上->更新庫存數量

  • 退貨與換貨流程

KEY IN退貨單->

  1. 為退貨->列印退貨單及收貨->確認貨品已經交回公司->更新庫存數量
  2. 為換貨->新增一筆出貨單->列印退貨單及出貨單以及備妥貨品->確認貨品已進行一收一出的動作->貨品入待驗區
  • 報表資訊

營業額報表(只含現金收入部份)

應收報表(只用於支票部份)

盤點表

    • 統計[已確認之出貨單-已出貨之確認單]的數量
    • 統計[未確認之出貨單-未出貨之確認單]的數量

2010年6月8日 星期二

[Javascript]如何 配合Client Button控制項取得CheckBoxList的值(With Client Button controls to obtain the value CheckBoxList)


問題
如何配合Client Button控制項取得CheckBoxList的值



解決方法
使用Javascript配合html的input button,處理方式是直接由Javascript以id取得CheckBoxList的控制項後,傳回已選擇的值
而前後者不同的是一個再Server端執行,一個則由Client處理完成,若網頁上的控制項很多,使用Server端的方式執行將會造成網路流量的增加,使用上須小心!

CheckBoxList控制項輸出到Client端的時候會像這樣參考
所以抓取的方式跟RadioButtonList是一樣的

.aspx如下:
  1. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>未命名頁面</title>
  6. </head>
  7. <script language="javascript">
  8.   //取得垂直排列的CheckBoxList值
  9.     function cilckbtnVertical()
  10.     {
  11.         var table;
  12.         var choiceitem="";
  13.         //取得並觸發按鍵動作
  14.         table=document.getElementById("CheckBoxList1");
  15.         for(i=0;i<table.rows.length;i++)
  16.         {
  17.             if(table.rows[i].cells[0].childNodes[0].checked == true)
  18.             {
  19.                 selValue = table.rows[i].cells[0].childNodes[0].value;
  20.                 choiceitem=choiceitem+" "+i;
  21.             }
  22.         }
  23.         if(choiceitem!="")
  24.         {
  25.             alert("已選擇:"+choiceitem);
  26.         }
  27.     }
  28.     //取得水平排列的CheckBoxList值
  29.     function cilckbtnHorizontal()
  30.     {
  31.         var table;
  32.         var choiceitem="";
  33.         //取得並觸發按鍵動作      
  34.         table=document.getElementById("CheckBoxList1");
  35.         for(i=0;i<table.rows[0].cells.length;i++)
  36.         {
  37.             if(table.rows[0].cells[i].childNodes[0].checked == true)
  38.             {
  39.                 selValue = table.rows[0].cells[i].childNodes[0].value;
  40.                 choiceitem=choiceitem+" "+i;
  41.             }
  42.         }
  43.         if(choiceitem!="")
  44.         {
  45.             alert("已選擇:"+choiceitem);
  46.         }
  47.     }
  48. </script>
  49. <body>
  50.     <form id="form1" runat="server">
  51.         <div>
  52.              <asp:CheckBoxList ID="CheckBoxList1" runat="server">
  53.             </asp:CheckBoxList><%--按下btnServerCall的時候去Postback候傳回變更後的Textbox值--%>
  54.             <%--按下btnJavaScriptCall的時候去觸發javascript--%>
  55.             <input id="btnJavaScriptCall" type="button" value="JavaScriptChoice1" onclick="cilckbtnVertical();" />
  56.         <%--<input id="Button1" type="button" value="JavaScriptChoice1" onclick="cilckbtnHorizontal();" />--%>
  57.             </div>
  58.     </form>
  59. </body>
  60. </html>
.cs如下:
  1. namespace WebApplication1
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.         protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.             if (!IsPostBack)
  8.             {
  9.                 for (int i = 0; i <= 3; i++)
  10.                 {
  11.                     ListItem lt = new ListItem();
  12.                     lt.Text = "選擇" + i.ToString();
  13.                     lt.Value =  i.ToString();
  14.                     this.CheckBoxList1.Items.Add(lt);
  15.                 }
  16.             }
  17.         }
  18.     }
  19. }

[Javascript]Client Button控制項比較TextBox控制項的值是否相等,若相等則跳出對話方塊,選擇是的話則觸發ASP.NET Button控制項(Compare the value of Client Button controls TextBox controls are equal, if equal then jump dialog box, select Yes, then the trigger ASP.NET Button controls)


問題
Client Button控制項比較TextBox控制項的值是否相等,若相等則跳出對話方塊,選擇是的話則觸發ASP.NET Button控制項



解決方法
使用Server端的控制項,處理方式是將Client的整個網頁傳回Server,然後在Server端變更RadioButtonList的值以後,再回傳整個網頁回來Client端
使用Javascript配合html的input button,處理方式是直接由Javascript以id取得2個要比較的Textbox控制項的值以後,經由判斷是否想等,若相等以後,則可選擇是否要觸發Server端的Button控制項
而前後者不同的是一個再Server端執行,一個則由Client處理完成,若網頁上的控制項很多,使用Server端的方式執行將會造成網路流量的增加,使用上須小心!

.aspx如下:
  1. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>未命名頁面</title>
  6. </head>
  7. <script language="javascript">
  8.    //比較兩值是否想等,若不相等,跳出Confirm視窗,若相等,觸發btnclick的事件
  9.     function IsEqual()
  10.     {
  11.         if(document.getElementById("TextBox1").value==document.getElementById("TextBox2").value)
  12.         {
  13.             //當兩值相等後,判斷是否傳回Server端
  14.             var r=confirm("是否執行回傳作業")
  15.             if (r==true)
  16.             {
  17.                 document.getElementById("btnServerCall").click();
  18.             }
  19.             else
  20.             {
  21.                 alert("已放棄回傳!")
  22.             }
  23.         }
  24.         else
  25.         {
  26.             alert("兩值不相等!!");
  27.         }
  28.     }
  29. </script>
  30. <body>
  31.     <form id="form1" runat="server">
  32.         <div>
  33.             &nbsp;<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><%--按下btnServerCall的時候去Postback候傳回變更後的Textbox值--%>
  34.             <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  35.             <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>&nbsp;
  36.             <%--按下btnJavaScriptCall的時候去觸發javascript--%>
  37.             <input id="btnJavaScriptCall" type="button" value="JavaScriptChoice1" onclick="IsEqual();" />
  38.             </div>
  39.     </form>
  40. </body>
  41. </html>
.cs如下:
  1. namespace WebApplication1
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.         protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.             if (!IsPostBack)
  8.             {
  9.             }
  10.         }
  11.         protected void Button1_Click(object sender, EventArgs e)
  12.         {
  13.             this.TextBox3.Text = "Service call";
  14.         }
  15.     }
  16. }

[Javascript]Button控制項與Javascript配合Client Button控制項取得RadioButtonList的值(Button controls and Javascript with Client Button controls to obtain the value of the RadioButtonList)


問題
Button控制項與Javascript配合Client Button控制項取得RadioButtonList的值



解決方法
使用Server端的控制項,處理方式是將Client的整個網頁傳回Server,然後在Server端變更RadioButtonList的值以後,再回傳整個網頁回來Client端
使用Javascript配合html的input button,處理方式是直接由Javascript取得RadioButtonList的控制項id後,直接取得值

而前後者不同的是一個再Server端執行,一個則由Client處理完成,若網頁上的控制項很多,使用Server端的方式執行將會造成網路流量的增加,使用上須小心!
RadioButtonList傳到Client後會解譯像下面這樣:
水平式:
  1. <table id="RadioButtonList1" border="0">
  2.     <tr>
  3.         <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="0" /><label for="RadioButtonList1_0">選擇0</label></td><td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_1">選擇1</label></td><td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_2">選擇2</label></td><td><input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="3" /><label for="RadioButtonList1_3">選擇3</label></td>
  4.     </tr>
  5. </table>
垂直式:
  1. <table id="RadioButtonList1" border="0">
  2.     <tr>
  3.         <td><input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="0" /><label for="RadioButtonList1_0">選擇0</label></td>
  4.     </tr><tr>
  5.         <td><input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_1">選擇1</label></td>
  6.     </tr><tr>
  7.         <td><input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_2">選擇2</label></td>
  8.     </tr><tr>
  9.         <td><input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="3" /><label for="RadioButtonList1_3">選擇3</label></td>
  10.     </tr>
  11. </table>
所以用Javascript的取RadioButtonList的值時候,也要注意顯示方向

.aspx如下:
  1. >
  2. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6.     <title>未命名頁面</title>
  7. </head>
  8. <script language="javascript">
  9.     //取得垂直排列的RadioButton值
  10.     function cilckbtnVertical()
  11.     {
  12.         var table;
  13.         //取得並觸發按鍵動作
  14.         table=document.getElementById("RadioButtonList1");
  15.         for(i=0;i<table.rows.length;i++)
  16.         {
  17.             if(table.rows[i].cells[0].childNodes[0].checked == true)
  18.             {
  19.                 selValue = table.rows[i].cells[0].childNodes[0].value;
  20.                 alert(selValue);
  21.                return;
  22.             }
  23.         }
  24.     }
  25.     //取得水平排列的RadioButton值
  26.     function cilckbtnHorizontal()
  27.     {
  28.         var table;         //取得並觸發按鍵動作         table=document.getElementById("RadioButtonList1");
  29.         for(i=0;i<table.rows[0].cells.length;i++)
  30.         {
  31.             if(table.rows[0].cells[i].childNodes[0].checked == true)
  32.             {
  33.                 selValue = table.rows[0].cells[i].childNodes[0].value;
  34.                 alert(selValue);
  35.                 return;
  36.             }
  37.         }
  38.     }
  39. </script>
  40. <body>
  41.     <form id="form1" runat="server">
  42.         <div>
  43.             <asp:RadioButtonList ID="RadioButtonList1" runat="server">
  44.             </asp:RadioButtonList>
  45.             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><%--按下btnServerCall的時候去Postback候傳回變更後的Textbox值--%>
  46.             <asp:Button ID="btnServerCall" runat="server" OnClick="Button1_Click" Text="ServerChoice1" />
  47.             <%--按下btnJavaScriptCall的時候去觸發javascript--%>             <input id="btnJavaScriptCall" type="button" value="JavaScriptChoice1" onclick="cilckbtnHorizontal();" />
  48.             <%--<input id="Button1" type="button" value="JavaScriptChoice1" onclick="cilckbtnVertical();" />--%>             </div>
  49.     </form>
  50. </body>
  51. </html>
.cs如下:
  1. namespace WebApplication1
  2. {
  3.    public partial class _Default : System.Web.UI.Page
  4.     {
  5.        protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.             if (!IsPostBack)
  8.             {
  9.                 for (int i = 0; i <= 3; i++)
  10.                 {
  11.                     ListItem lt = new ListItem();
  12.                     lt.Text = "選擇" + i.ToString();
  13.                     lt.Value = i.ToString();
  14.                     this.RadioButtonList1.Items.Add(lt);
  15.                 }
  16.             }
  17.         }
  18.         protected void Button1_Click(object sender, EventArgs e)
  19.         {
  20.             this.TextBox1.Text = "Service call";             this.RadioButtonList1.SelectedValue = "1";         }
  21.     }
  22. }

[Javascript]Button控制項與Javascript配合Client Button控制項變更Textbox的值(Button controls and Javascript with Client Button controls to change the value Textbox)


問題
Button控制項與Javascript配合Client Button控制項變更Textbox的值



解決方法
使用Server端的控制項,處理方式是將Client的整個網頁傳回Server,然後在Server端變更Textbox的值以後,再回傳整個網頁回來Client端
使用Javascript配合html的input button,處理方式是直接由Javascript取得要變更的控制項id後,直接給值
而前後者不同的是一個再Server端執行,一個則由Client處理完成,若網頁上的控制項很多,使用Server端的方式執行將會造成網路流量的增加,使用上須小心!
.aspx如下:
  1. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>未命名頁面</title>
  6. </head>
  7. <script language="javascript">
  8.     function cilckbtn(btnID)
  9.     {
  10.         var myText=null
  11.         //取得並觸發按鍵動作
  12.         myText="Javascript call me"
  13.         document.getElementById(btnID).value=myText;
  14.     }
  15. </script>
  16. <body>
  17.     <form id="form1" runat="server">
  18.         <div>
  19.             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  20.             <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  21.            <%--按下btnServerCall的時候去Postback候傳回變更後的Textbox值--%>
  22.             <asp:Button ID="btnServerCall" runat="server" OnClick="Button1_Click" Text="ServerCall" />
  23.            <%--按下btnJavaScriptCall的時候去觸發javascript--%>
  24.             <input id="btnJavaScriptCall" type="button" value="JavaScriptCall" onclick="cilckbtn('TextBox1');"/></div>
  25.     </form>
  26. </body>
  27. </html>
.cs如下:
  1. namespace WebApplication1
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.         protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.         }
  8.         protected void Button1_Click(object sender, EventArgs e)
  9.         {
  10.             this.TextBox1.Text = "Service call me";
  11.         }
  12.     }
  13. }

[Javascript]JavaScript自動觸發Server端Button(Server-side JavaScript automatically trigger Button)


問題
JavaScript自動觸發Server端Button



解決方法
程式流程是這樣的:
Server端將程式碼與html結合後,再將畫面傳送到Client端顯示,所以當Server的aspx頁面的PageLoad的時候,第一次執行,所以取得變數postback="clickbtn();"(這是執行在client端的Javascript Function),因此在結合程式與html的時候,透過<script><%=postback%></script> 傳值給Javascript(在此因為將之設為clickbtn();所以會觸發Javascript呼叫該Function)

.aspx如下:
  1. <%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head runat="server">
  5.     <title>未命名頁面</title>
  6. </head>
  7. <script language="javascript">
  8.     function cilckbtn()
  9.     {
  10.     //取得並觸發按鍵動作
  11.     var btn=document.getElementById("Button1");
  12.     btn.click();
  13.     }
  14. </script>
  15. <body>
  16.     <form id="form1" runat="server">
  17.         <div>
  18.             <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
  19.             <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
  20.     </form>
  21. <%--在頁面載入的時候去觸發javascript--%>
  22. <%--使用ispostback配合變數去是否執行過javascript--%>     <script><%=postback%></script>
  23. </body>
  24. </html>
.cs如下:
  1. namespace WebApplication1
  2. {
  3.     public partial class _Default : System.Web.UI.Page
  4.     {
  5.        protected void Page_Load(object sender, EventArgs e)
  6.         {
  7.             if (IsPostBack)
  8.             {
  9. //若執行過則將變數改為空白,在頁面重新載入的時候,就不會觸發javascript  postback = string.Empty;
  10.             }
  11.         }
  12.         protected void Button1_Click(object sender, EventArgs e)
  13.         {
  14.             this.Label1.Text = "click button";
  15.         }
  16.         public string postback = "cilckbtn();";
  17.     }
  18. }
瀏覽器後Label會被改掉!就是因為傳到Client端的時候,已經被觸發,導致再做一次postbak去變更Label的字

[ASP.NET]不用Javascript就可以控制table顯示與否(Javascript can not control whether or not the display table)


問題

不用Javascript就可以控制table顯示與否



解決方法

當我們在一般的HTML TAG裡,加上ID以後,在RUNAT="SERVER"時,在ASP.NET的.CS檔案裡,就能繫結到此TAG,進而控制各項屬性!如下圖:

Capture1

Capture
.aspx設計畫面如下:
col1 col2 c0l3
row1 row1 row1
row2 row2 row2
.aspx的原始檔如下:
  1. <table>
  2.            <tr>
  3.                <td style="width: 100px">
  4.                    col1</td>
  5.                <td style="width: 100px">
  6.                    col2</td>
  7.                <td style="width: 100px">
  8.                    c0l3</td>
  9.            </tr>
  10.            <tr>
  11.                <td style="width: 100px; height: 21px">
  12.                    row1</td>
  13.                <td style="width: 100px; height: 21px">
  14.                </td>
  15.                <td style="width: 100px; height: 21px">
  16.                </td>
  17.            </tr>
  18.            <tr id="show_on" runat="server">
  19.                <td style="width: 100px">
  20.                    row2</td>
  21.                <td style="width: 100px">
  22.                </td>
  23.                <td style="width: 100px">
  24.                </td>
  25.            </tr>
  26.        </table>
  27.  
.cs程式碼如下:
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.     this.show_on.Visible = false;
  4. }
  5.  

2010年6月6日 星期日

[6421:Windows Server 2008網路基礎架構組態與疑難排除] Module2-Lesson2 : Configuring the DNS Role


2-10。What Are the Components of a DNS Solution?
2-10 What Are the Components of a DNS Solution

2-11。DNS Resource Records
DNS resuirce records include:
  • SOA:Start of Authority(1Zone一定只有1筆)
  • A:Host Record(為IPV4的IP命名)
  • CNAME:Alias Record(已被命名後,可取別名)
  • MX:Mail Exchange Record(若有架Mail Server則要記錄)
  • SRV:Service Resource(註冊位置識別AD)
  • NS:Name Servers(1~N筆作為備援用)
  • AAAA:IPv6 DNS Record(為IPV6的IP命名)

2-12。What Are Root Hints
Root Hints contain the IP address for DNS root servers
2-12 What Are Root Hints

2-13。What Is a DNS Query?
A query is a request for name resolution and is directed to a DNS Server
  • Queries are recursive or iterative
  • DNS Client and DNS servers both initiate queries
  • DNS servers are authoritative or nonauthoritative for a namespace
  • An authoritative DNS server for the namespace will either:

    • Return the requested IP address
    • Return an authoritative “NO”
  • A nonauthoritative DNS server for the namespace will either:

    • Check its cache
    • Use forwarders
    • Use root hints

MyNote
  • What Is a DNS Query?
  • 2-13 What Is a DNS Query

2-14。What Are Recursive Queries?
A recursive query is sent to a DNS server and requires a complete answer
2-14 What Are Recursive Queries

2-15。What Are Iterative Queries ?
A iterative query directed to a DNS server may be answered with a referral to another DNS Server
2-15 What Are Iterative Queries

2-16。What Is a Forwarder?
A forwarder is a DNS server designated to resolve external or offsite DNS domain names
2-16 What Is a Forwarder

2-17。What Is a Conditional Forwarding?
Conditional forwarding forwards requests using a domain name condition
2-17 What Is a Conditional Forwarding

MyNote
  • Conditional Forwarding?

    • 依據要查詢名稱的尾碼,優先交給設定的DNS Server查
  • Forwarder避免犯的錯誤:

    • 2-17 What Is a Conditional Forwarding mynote
  • command prompt windows 底下:

    • ipconfig /displaydns(顯示DNS IP)
    • ipconfig /flushdns(清除DNS快取)

2010年6月5日 星期六

[6421:Windows Server 2008網路基礎架構組態與疑難排除]Module2-Lesson1 : Installing the DNS Server Role


2-4。Overview of the Domain Name System Role
Domain Name System is a hierarchical distributed database
  • DNS is the foundation of Internet naming scheme
  • DNS supports accessing resources by using alphanumeric names
  • InterNIC is responsible for managing the domain namespace
  • DNS was created to support the Internet’s growing

2-5。Overview the DNS Namespace
2-5 Overview of the DNS Namespace

2-6。DNS Imporvements for Windows Server 2008
New or enhanced feature in the Windows Server 2008 version of DNS include:
  • Background zone loading
  • IP version 6 support
  • Support for read-only domain controllers
  • Global single names


2-8。Considerations for Deploying the DNS Server Role
  • The user account must be a member of the local administrator group or equivalent
  • Manually configuring the server to use a static IP address is recommended
  • Manually editing the server and boot files is not recommended
  • Use the DNS console or dnscmd
  • Active Directory-integrated DNS zone cannot be administered using a text editor

MyNote
  • DNS:Domain Name System:


    • 用途:解析1個主機或服務(等)在哪裡的資訊
    • 實際上,它是一種"特定用途"的階層分散式網路資料庫系統(採Client/Server 架構)
階層分散式:1.管理分散2.儲存分散3.查詢分散
  • Internet DNS Namespace:


    • 將Internet的主機,服務等,命名後,由這些名字邏輯組織而成的結構
    • 階層式,只管自己直接的下層,最上層為root(。)
  • DNS Domain:


    • 在DNS Namespace中,1個可含有下層的節點=>一群共用相同尾碼的集合
  • FQDN(Fully Quailed Domain Name):


    • 在DNS Namespace中,1個節點的完整名稱(規則:由下往上每層加"."隔開)
  • ZONE:


    • 因分散管理或分散儲存的需求,將Namespace切割的連續區域
    • 不同的zone可以委派不同的人管理
    • 不同的zone必有獨立的資料儲存區(不同的檔或AD終不同的容器)
  • 下圖為總整理: 
2-5 MyNote
相同名稱的尾碼=>Domain
程式開發走Socket API=>要靠DNS解析
NetBIOS(配合WINS)=>IBM開發,從2000被捨棄,無階層
  • Virtual PC連網路方法:
    • 1.連接到實體電腦(HOST:注意電腦名曾不得重複)
    • 2.接到虛擬ID分享器(NAT:IP要自動取得)
    • 3.新增Microsoft Lookup Adapter :
      • 1.Start=>Control Panel=>Add Hardware=>Next=>Yes,xxxx=>Add a new Hardware Device=>Next=>Network Adapter=>Microsoft=>Lookup Adapter
      • 2.安裝好後,設定IP Address跟subnet mask:
        • a.關閉Firewall=>net firewall set opmode disable
        • b.停止服務=>sc stop sharedaccess
        • c.關閉服務=>sc config sharedaccess start= disabled
      • 3.啟動Routing and Remote Access:
        • a.Start=>run=>rrasmamt.msc
        • b.對SVRX=>右鍵Configure and Enable xxx=>選最底下=>Next=>選最底下=>Finish
      • 4.安裝好後,IP Routing底下=>General=>右鍵New Routing portcal=>NAT/Base Firewall=>Next=>會多一個NAT/Basic Firewall=>右鍵New Interface=>選擇網路連線=>選Host的連線,點對外=>Next=右鍵New Interface=>選擇網路連線=>選Lookup Adapter的網路連線,點對內
      • 5.在Virtual PC裡,網路卡改為Microsoft Lookup Adapter
      • 6.測試:
        • 在SVRXX裡,Command Prompt windows底下:
        • nslookup=>server nyc-svrxx(用自己的dns server)=>www.uuu.com.tw(查對外網路是否接的出去)

2010年6月4日 星期五

[Javascript]對話視窗(show confirm windows)


問題
對話視窗



解決方法
  1. <script type="text/javascript">
  2. function show_confirm()
  3. {
  4.     var r=confirm("Press a button!");
  5.     if (r==true)
  6.     {
  7. alert("You pressed OK!");
  8.     }
  9.     else
  10.     {
  11. alert("You pressed Cancel!");
  12.     }
  13. }
  14. </script>

[ASP.NET]VB.NET 顯示文字訊息(Show MessageBox)


問題

VB.NET 顯示文字訊息



解決方法

在用戶端顯示訊息正確的方法是要使用 RegisterStartupScript 方法來輸出 JavaScript 的 alert 函式。
  1. Me.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "alert('授權狀態已為授權成功者,不允許異動專案')", True)

熱門文章