my concern is about post-back. I have 3 textboxes, the last name, first name and username. I want to combine last name and first name to create a username have lastname.firstname format. My code in .aspx is as follows. The post-back is true for first name because after the user enters the first name, it will automatically generate the username.
<strong>LAST NAME: <span style="color: #FF0000">*</span> </strong>
<asp:TextBox ID="txtLname" runat="server"
Width="197px" onkeypress="return Alphabet()" BorderStyle="Solid"></asp:TextBox>
<strong>FIRST NAME: <span style="color: #FF0000">*</span> </strong> <asp:TextBox ID="txtFname" runat="server" Width="199px"
onkeypress="return Alphabet()" AutoPostBack="True"
ontextchanged="txtFname_TextChanged" BorderStyle="Solid"></asp:TextBox>
<strong>USERNAME: </strong> <asp:TextBox
ID="txtUser" runat="server"
Width="225px" ReadOnly="True" style="margin-left: 6px" BorderStyle="Solid" onkeypress="return Alphabet()"></asp:TextBox>
My code in .aspx.cs is as follows.
protected void txtFname_TextChanged(object sender, EventArgs e)
{
string mystring = txtFname.Text;
mystring = Regex.Replace(mystring, @"\s+", "");
txtUser.Text = txtLname.Text + "." + mystring;
}
this is to trigger the automatic generation of username.
To sum it up, I want to know how to stop post-back from going back to the top of the page after entering the first name for automatic generation of username. thank you very much.