1

我想在文本框中的文本更改上使用文本框连接 VB.Net 中的文本字段。

目前我正在做下拉选择更改的任务:

VB代码

Protected Sub ddlCitizenSex_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCitizenSex.SelectedIndexChanged
    If ddlCitizenSex.SelectedValue = "Male" Then
        txtCitizenName.Text = 
            txtCitizenFirstName.Text + " " + "S/O" + 
            txtCitizenFatherName.Text + " " + "S/O" + 
            txtCitizenGFatherName.Text + " " + txtCitizenFamilyName.Text
    Else
        txtCitizenName.Text = 
            txtCitizenFirstName.Text + " " + "D/O" +
            txtCitizenFatherName.Text + " " + "S/O" + 
            txtCitizenGFatherName.Text + " " + txtCitizenFamilyName.Text
    End If
End Sub

我写了下面的代码来试试,但没有用:

VB代码

Private Sub ModifyCitizenName()
    If ddlCitizenSex.SelectedValue = "Male" Then
        txtCitizenName.Text = 
            txtCitizenFirstName.Text + " " + "S/O" + 
            txtCitizenFatherName.Text + " " + "S/O" + 
            txtCitizenGFatherName.Text + " " + txtCitizenFamilyName.Text
    Else
        txtCitizenName.Text = 
            txtCitizenFirstName.Text + " " + "D/O" + 
            txtCitizenFatherName.Text + " " + "S/O" + 
            txtCitizenGFatherName.Text + " " + txtCitizenFamilyName.Text
    End If
End Sub

Protected Sub txtCitizenFirstName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCitizenFirstName.TextChanged
    ModifyCitizenName()
End Sub

Protected Sub txtCitizenFamilyName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCitizenFamilyName.TextChanged
    ModifyCitizenName()
End Sub

ASP 代码

 <asp:Label ID="lblCitizenFamilyName" runat="server"  Text="">Family Name</asp:Label>
    <asp:TextBox ID="txtCitizenFamilyName"  AutoPostBack="true" runat="server"></asp:TextBox>

    <asp:Label ID="lblCitizenFirstName" runat="server"  Text="">First Name</asp:Label>
    <asp:TextBox ID="txtCitizenFirstName"  AutoPostBack="true" runat="server"></asp:TextBox>

    <asp:Label ID="lblCitizenSex" runat="server" Text="">Sex</asp:Label>
    <asp:DropDownList ID="ddlCitizenSex" runat="server"></asp:DropDownList>

如您所见,我在两个文本框中都使用了AutoPostBack 。

我是否必须使用<Triggers>文本框。

以及如何执行任务。希望大家帮忙。谢谢

4

1 回答 1

2

ASP.NET 不会触发回发,因为用户已经编辑了文本框的内容。如果是这样,那么每次您输入一个字符时,您都必须等待大约 2 秒,因为执行了完整的往返。

此功能(使用 JavaScript (尤其是 jQuery 库)最好在客户端实现使用 的内容更新文本框。Knockout.js也可用于轻松地将Observer添加到您的txtCitizenFamilyName文本框,这将允许您轻松实现这一点。

于 2012-08-14T09:33:55.340 回答