Textbox,TextChanged事件未触发 [英] Textbox,TextChanged event not firing
问题描述
请帮我这个,我有3个文本框,即txtLastname,txtFirstname和txtUsername我希望我的txtUsername在提供txtLastname和txtFirstname的数据后自动填充,格式应为txtLastname_txtFirstname(txtFirstname中的前两个字母),这里是我正在使用的代码:
aspx:
< asp:TextBox ID = txtUsername runat = server 宽度 = 250px
ontextchanged = txtUsername_TextChanged AutoPostBack = true > < / asp:TextBox >
cs文件:
< pre lang =cs> protected void txtUsername_TextChanged( object sender,EventArgs e)
{
txtUsername.Text = txtLastName.Text + _ + txtFirstName.Text;
}
它应如下所示:
< asp:textbox id = txtFirstname runat = server > < / asp:textbox >
< asp: textbox id = txtLastname runat = server autopostback = true ontextchanged = txtLastname_TextChanged > < span class =code-keyword>< / asp:textbox >
< asp:textbox id = txtUsername runat = server width = 250px > < / asp:textbox >
protected void txtLastname_TextChanged( object sender,EventArgs e)
{
txtUsername.Text = txtLastName.Text + _ + txtFirstName.Text;
}
问候..:)
如果您希望在更改值时自动更改用户名的文本框对于 txtLastname,txtFirstname 而不是txtUsername,应为txtLastname,txtFirstname创建 ontextchanged 事件。
见下面代码:
ASPX代码:
< asp:TextBox ID = txtLastname runat = 服务器 宽度 = 250px
ontextchanged = txtName_TextChanged AutoPostBack = true > < / asp:TextBox >
< asp:TextBox ID = txtFirstname runat = server 宽度 = 250px < span class =code-attribute>
< span class =code-attribute> ontextchanged = txtName_TextChanged AutoPostBack= true > < / asp:TextBox >
< asp:TextBox ID = txtUsername < span class =code-attribute> runat = server 宽度 = 250px
AutoPostBack = true > < / asp:TextBox >
CS代码:
protected void txtName_TextChanged( object sender,EventArgs e)
{
this .txtUsername.Text = this .txtLastname.Text + _ + 此跨度> .txtFirstname.Text;
}
试试这个:
将你的逻辑放在firstname和lastname文本框文本上。
Please help me with this, I have 3 textboxes namely txtLastname,txtFirstname and txtUsername I want my txtUsername to automatically be filled after supplying data for txtLastname and txtFirstname the format should be txtLastname_txtFirstname(The first two letters in txtFirstname), here's the code I'm using:
aspx:
<asp:TextBox ID="txtUsername" runat="server" Width="250px"
ontextchanged="txtUsername_TextChanged" AutoPostBack="true"></asp:TextBox>
cs file:
protected void txtUsername_TextChanged(object sender, EventArgs e)
{
txtUsername.Text = txtLastName.Text + "_" + txtFirstName.Text;
}
It should be like follows:
<asp:textbox id="txtFirstname" runat="server" ></asp:textbox> <asp:textbox id="txtLastname" runat="server" autopostback="true" ontextchanged="txtLastname_TextChanged" ></asp:textbox> <asp:textbox id="txtUsername" runat="server" width="250px" ></asp:textbox>
protected void txtLastname_TextChanged(object sender, EventArgs e) { txtUsername.Text = txtLastName.Text + "_" + txtFirstName.Text; }
Regards..:)
If you want textbox for username to be changed automatically on changing the value of the txtLastname, txtFirstname than you should create ontextchanged event for txtLastname, txtFirstname instead of txtUsername.
See below code :
ASPX Code :
<asp:TextBox ID="txtLastname" runat="server" Width="250px" ontextchanged="txtName_TextChanged" AutoPostBack="true"></asp:TextBox> <asp:TextBox ID="txtFirstname" runat="server" Width="250px" ontextchanged="txtName_TextChanged" AutoPostBack="true"></asp:TextBox> <asp:TextBox ID="txtUsername" runat="server" Width="250px" AutoPostBack="true"></asp:TextBox>
CS Code :
protected void txtName_TextChanged(object sender, EventArgs e) { this.txtUsername.Text = this.txtLastname.Text + "_" + this.txtFirstname.Text; }
Try this :
put your logic on firstname and lastname textbox text changed.
这篇关于Textbox,TextChanged事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!