2015年8月26日 星期三

javascript 控制是否要啟用驗證控制項

javascript:
        $(document).ready(function () {
            if ($('#txt2').val() == '') {
                ValidatorEnable($('#rfvtxt')[0], true);

            } else
                ValidatorEnable($('#rfvtxt')[0], false);
            $('#txt2').change(function () {
                if ($('#txt2').val() =='') {
                    ValidatorEnable($('#rfvtxt')[0], true);

                } else
                    ValidatorEnable($('#rfvtxt')[0], false);
            });
        });
        function validatePage() {
            var flag = Page_ClientValidate("aaa");
            return flag;
        }
html:


    <asp:RequiredFieldValidator runat="server" ID="rfvtxt" ControlToValidate="TXT" ErrorMessage="*"   ValidationGroup="aaa"  Enabled="false"></asp:RequiredFieldValidator>
        <asp:Button runat="server" OnClick="Unnamed_Click"   OnClientClick="javascript:return validatePage();"/>


cs.
 Page.Validate();
        if (!Page.IsValid)
        {
            return;
        }


寫成function做法
http://techbrij.com/client-side-validation-using-asp-net-validator-controls-from-javascript



2015年8月11日 星期二

分頁

  //分頁格式水平數字擺設樣式1處理方法。
    //版本:v1.0;日期:20091116;作者:Wesley0917;說明:建立方法
    //撰寫語言:ASP.NET2.0
    //輸入1:索引頁面數。
    //輸入2:總分頁數。
    //輸入3:分頁顯示的筆數。
    //輸入4:要傳遞的網址頁面字串。
    //結果0:輸出分頁後水平數字擺設樣式。
    //範例0:CutPageStyle1Horizontal_Md(Request["Page"], "32", "10", "Default2.aspx?") 。結果:[前十頁]11 12 [13] 14 15 16 17 18 19 20 [後十頁]
    public static string CutPageStyle1Horizontal_Md(string strPageIndex_Val, string strTotalPages_Val, string strPageShowCounts_Val, string strURL_Val)
    {
        //宣告整數變數。(目前在第幾頁)
        int intPageIndex = Convert.ToInt32(strPageIndex_Val);
        //宣告整數變數。(資料的總頁數。搜尋到的資料,共需要「幾頁」才能全部呈現)
        int intPages = Convert.ToInt32(strTotalPages_Val);
        //宣告整數變數。(分頁顯示的筆數整數值)
        int intPageShowCounts = Convert.ToInt32(strPageShowCounts_Val);
        //宣告字串變數。(組合字串用)
        string strValue1 = null;
        string strValue2 = null;
        string strValue3 = null;

        //宣告整數變數。(十進位字數區隔)
        int intBlockPage = 0;
        //取得十進位數字結果。(例如:1~10=0; 11~20=1; 21~30=2)
        //取得除法的整數成果(商),如果有餘數則不去管它。
        intBlockPage = intPageIndex / intPageShowCounts;

        //當十進位數字大於0時,表示不是1~10的範圍。
        if (intBlockPage > 0)
        {
            //輸出結果。(前十頁的超連結)
            strValue1 = "<a href=" + strURL_Val + "Page=" + (((intBlockPage - 1) * intPageShowCounts) + (intPageShowCounts - 1)) + "> [前" + intPageShowCounts.ToString() + "頁]  </a>  ";
        }

        //以十進位為單位顯示所有號碼。0~10
        for (int K = 0; K <= intPageShowCounts; K++)
        {
            //當(十進位字數加上0~10迴圈單位數字)小於等於資料總頁數(intPages)範圍內時。例如:(2*10+1) <=43
            if ((intBlockPage * intPageShowCounts + K) <= intPages)
            {
                //當(十進位字數加上0~10迴圈單位數字)等於(目前在第幾頁)時。
                if (((intBlockPage * intPageShowCounts) + K) == intPageIndex)
                {
                    //組合字串結果。(目前頁次的超連結前後加上[ ]符號)
                    strValue2 += "[<b>" + intPageIndex + "</b>]" + "   ";
                }
                else
                {
                    //當(十進位字數加上0~10迴圈單位數字)不等於0時。
                    if (((intBlockPage * intPageShowCounts) + K) != 0)
                    {
                        //組合字串結果。(目前頁次範圍的數字超連結)
                        strValue2 += "<a href=" + strURL_Val + "Page=" + (intBlockPage * intPageShowCounts + K) + ">" + (intBlockPage * intPageShowCounts + K) + "</a>  ";
                    }
                }
            }
        }

        //當(十進位數字)小於等於總頁次時。
        if ((intBlockPage < (intPages / intPageShowCounts)) & (intPages >= (((intBlockPage + 1) * intPageShowCounts) + 1)))
        {
            //組合字串結果。(後十頁的超連結)
            strValue3 = "  <a href=" + strURL_Val + "Page=" + ((intBlockPage + 1) * intPageShowCounts + 1) + ">  [後" + intPageShowCounts.ToString() + "頁]  </a>";
        }

        //傳回結果。
        return strValue1 + strValue2 + strValue3;
    }