0

1 から 100 までのページサイズを検証するために JavaScript を使用して検証を作成しています。

<script type="text/javascript" language="javascript">
    function validatePageSize() {
        var pageSize = document.getElementById('MainContent_txtPageSize').value;
        var errorCtr = 0;
        if (pageSize == "") {
            alert('Records per page should be a valid number');
            errorCtr++;
        }
        if (pageSize < 0 || pageSize > 100) {
            alert('Records per page should be between 1 to 100');
            errorCtr++;
        }
        if (errorCtr == 0) {
            //missing code
        }
    }
</script>

コードビハインド:

void GotoPage()
{
    if (txtPageSize.Text.Trim() != "0" && txtPageSize.Text.Trim().Length > 0)
    {
        GridView1.PageSize = Convert.ToInt16(txtPageSize.Text.Trim());
        GetPOHistoryByParameterOrderByPONumber();
        btnShowAll.Visible = false;
    }
    else
    {
        GridView1.PageSize = 100;
        GetPOHistoryByParameterOrderByPONumber();
        btnShowAll.Visible = false;
        txtPageSize.Text = "100";
    } 
}
4

4 に答える 4

0

こうやってみて、

WebForm2.aspx ページ:-

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
<script type="text/javascript">
    function validatePageSize() {
        var pageSize = document.getElementById('MainContent_txtPageSize').value;
        var errorCtr = 0;
        if (pageSize == "") {
            alert('Records per page should be a valid number');
            errorCtr++;
        }
        if (pageSize < 0 || pageSize > 100) {
            alert('Records per page should be between 1 to 100');
            errorCtr++;
        }
        if (errorCtr == 0) {
            PageMethods.Goto();
        }
    }
</script>
<div>
    <asp:TextBox ID="MainContent_txtPageSize" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="validatePageSize();" />
</div>
</form>

WebForm2.aspx.cs ページ:-

System.Web.Services を使用して追加します。

 [WebMethod]
    public static void Goto()
    {
        if (txtPageSize.Text.Trim() != "0" && txtPageSize.Text.Trim().Length > 0)
        {
            GridView1.PageSize = Convert.ToInt16(txtPageSize.Text.Trim());
            GetPOHistoryByParameterOrderByPONumber();
            btnShowAll.Visible = false;
        }
        else
        {
            GridView1.PageSize = 100;
            GetPOHistoryByParameterOrderByPONumber();
            btnShowAll.Visible = false;
            txtPageSize.Text = "100";
        } 
    }
于 2013-07-11T05:34:54.793 に答える