Get current TextBox Text value in a button onClick event - asp.net

anneliBlinaig

New Member
I have such a page \[code\]<form runat="server" id="NewForm"> Name: <asp:TextBox ID="Name" runat="server"></asp:TextBox> <asp:Button ID="AddNewName" runat="server" Text="Add" OnClick="AddNewName_Click" /> <asp:Label ID="NewName" runat="server"></asp:Label></form>\[/code\]In the code behind, I have a Page_Load which assign a value to the TextBox Name.\[code\]protected void Page_Load(object sender, EventArgs e){ Name.Text = "Enter Your Name Here";}\[/code\]Then upon the Click on the button AddNewName, I will write it in the Label NewName\[code\]protected void AddNewDivision_Click(object sender, EventArgs e){ NewName.Text = Name.Text;}\[/code\]But, no matter what I input in the Name TextBox, the Label only displays "Enter Your Name Here". It never updates to the actual content in the Name TextBox. What am I doing wrong with this code?
 
Back
Top