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;
}