FindControl 并将文本框更改为整数?

FindControl & Change Textbox to Integer?

我对此很陌生,FindControl 完全让我感到困惑。任何人都可以告诉我将文本框的输入更改为代码应该是什么: txtamount 为一个名为 'increment' 的整数。我什至找不到控件。我尝试过 Ctype、Cint LoginView1.Findcontrol 等,但没有任何乐趣。任何帮助表示赞赏。这是前端,然后是 VB 代码...

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent"Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent"Runat="Server">

<div style="text-align:center;">

    <asp:LoginView ID="LoginView1" runat="server">
        <AnonymousTemplate>
            <h2>Please <asp:HyperLink ID="HyperLink2" runat="server"         NavigateUrl="~/register-account.aspx" CssClass="boldStyle">REGISTER</asp:HyperLink> or <asp:HyperLink ID="hypLogin" runat="server" CssClass="nyroModal boldStyle" NavigateUrl="~/login2.aspx?page=vipseller">LOG IN</asp:HyperLink></h2>

        </AnonymousTemplate>
        <LoggedInTemplate>
             <h1>Shop Keeper<h1>
             <h2>Enter cash amount being spent or redeemed by customer:</h2>

             <asp:TextBox ID="txtAmount" runat="server" MaxLength="15" TabIndex="8" ></asp:TextBox>
             <br><br>

             <asp:Button ID="btnSpent" runat="server" Text="Spent" TabIndex="10" CssClass="button greyShaded" onclick="AddPoints_Click" />
             <asp:Button ID="btnRedeemed" runat="server" Text="Redeem" TabIndex="10" CssClass="button greyShaded" /><br><br>
        </LoggedInTemplate>
    </asp:LoginView>
</div>
</asp:Content>

VB代码

Protected Sub AddPoints_Click(sender As Object, e As EventArgs)
   dim increment as integer = Cint(LoginView1.FindControl("txtamount"))
   response.write(increment)

FindControl,顾名思义,试图找到一个控件,而控件不是可以转换为整数的东西

Dim tb As TextBox = DirectCast(LoginView1.FindControl("txtamount"), TextBox)
if tb IsNot Nothing Then
   response.write(CInt(tb.Text))

我还建议添加一个 RangeValidator 以确保输入仅由有效数字组成。