Autometically remove default text from textbox
In C# how to remove default text autometically from textbox when user select a textbox to enter someone.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Mar 20, 2013, 2:12 PM EDT
When you create it, you need to add an extra line to 'wire up' the Enter event:
txtDynamic.Enter += txtDynamic_Enter;
You now need to add the handler manually rather than via the VS designer as you would with 'static' textboxes:
private void txtDynamic_Enter(object sender, EventArgs e)
{
TextBox tb = (TextBox)sender;
tb.Text = "";
}
Note that you can use the same event handler for any number of dynamic textboxes. The 'sender' parameter knows which one is being entered.
VulpesRank #55 · 29.2K reputationPosted Mar 19, 2013, 8:33 AM EDT
Arun Kurmi96 reputationPosted Mar 20, 2013, 9:34 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 20, 2013, 8:12 PM EDT
hi,
if your are web developer than you can use onclick or onfocus event of javascript.
or
if you are window form developer than above approch is good one.
Arun Kurmi96 reputationPosted Mar 21, 2013, 4:08 AM EDT
I give name for dynamic textbox txt1,txt2,.......so control called as txt1,txt2,......
i tried to wire control different types as commented in below code but not solve my problem.
Again thanks in advance.
for (int i = 0; i < n; i++)
VulpesRank #55 · 29.2K reputationPosted Mar 21, 2013, 8:03 AM EDT