Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi,
 
I am new to asp.net.and this question seems pretty silly, but I really can't figure out what is wrong.
 
I am having an issue with clearing the textbox.
I tried textbox.text=string.empty, textbox.text="" but none of these seem to help, the textbox just doesn't get cleared.
 
Can someone tell me if I have set something in the code that's not allowing me to clear the textbox?
 
[Edit: added code snippet from comments below - Henry]
<asp:TextBox ID="TextBox3" runat="server" Width="177px" ontextchanged="TextBox3_TextChanged" Height="16px" style="margin-left: 5px"></asp:TextBox> 
 
 protected void Button11_Click(object sender, EventArgs e)
 {
   Panel1.Visible = false; DropDownList5.ClearSelection();
   TextBox3.Text = string.Empty;
 }
[/Edit]
Posted 23-Nov-10 2:40am
Edited 23-Nov-10 23:19pm
v5
Comments
PogoboyKramer at 23-Nov-10 7:57am
   
Could you provide the code that you use? Specifically, we would like to see the html tag that defines your textbox, and the code behind that you are calling(Where your textbox.text=string.Empty) would be found, for example. It would make providing an answer much easier as the methods you describe should work if implemented properly.
csupriya at 23-Nov-10 8:15am
   
<asp:TextBox ID="TextBox3" runat="server" Width="177px"
ontextchanged="TextBox3_TextChanged" Height="16px"
style="margin-left: 5px"></asp:TextBox>
 

protected void Button11_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
DropDownList5.ClearSelection();
TextBox3.Text = string.Empty;

}
PogoboyKramer at 23-Nov-10 10:52am
   
What is happening in your ontextchanged handler? It may be part of the issue.
Dalek Dave at 24-Nov-10 4:19am
   
Edited for Grammar and Spelling.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Smile | :) Txtbxclearfilesafter.Clear(); Smile | :)
 
in place of txtbxclearfileafter write the name of ur textbox.......
  Permalink  
v4
Comments
csupriya at 23-Nov-10 7:54am
   
ok..in place of txtbxclearfileafter i wrote textbox3..but the intellisense doesnt give me clear()...:S
sujeet101 at 23-Nov-10 7:58am
   
where u write the code ?
can u send the code?
csupriya at 23-Nov-10 8:15am
   
<asp:TextBox ID="TextBox3" runat="server" Width="177px"
ontextchanged="TextBox3_TextChanged" Height="16px"
style="margin-left: 5px"></asp:TextBox>
 

protected void Button11_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
DropDownList5.ClearSelection();
TextBox3.Text = string.Empty;

}
Dalek Dave at 24-Nov-10 4:19am
   
Good Answer.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Problem Looking Strange For me..,
 
May be your all controls not set as runat server
 
here is the code i am providing just done on my PC
 
protected void Button1_Click(object sender, EventArgs e)
 {
     TextBox1.Text = String.Empty;
     TextBox2.Text = String.Empty;
 }
 

HTML Code
 
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:TextBox ID="TextBox2"
            runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server"
            Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>
 

It's working For me....
  Permalink  
Comments
Ankur\m/ at 23-Nov-10 23:51pm
   
[moved from answer];
OP wrote:
@Rajesh:
 
all my controls have runat="server"
does the fact that my controls are in a view have anything to do with this problem??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

protected void Button1_Click(object sender, EventArgs e) 
{
Textbox1.Text="";//this for clear the text box
DropDownList1.ClearSelection();
}//this for clear thr dropdownlist  
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 8

Hi Gowri,
 
if you give first priority for below code,
 
Panel1.Visible = false;
 
then upcoming inner part will not work.
 
so, if you want panel visible is false, then use after it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

you will find it over here
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

Hi, Use normal html reset control for clearing textbox values in client side.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I don't know why you are facing problem u have written right.
Can u tell me on which event u have called clearing text?
  Permalink  
Comments
csupriya at 23-Nov-10 7:55am
   
i have called it in button_click event..
Mohd Wasif at 23-Nov-10 7:59am
   
Make Function as
Void Clear()
{
txtbox1.Text="";
txtBox2.Text="";
}
 
call this function on click event Hope it will run.
Mohd Wasif at 23-Nov-10 8:04am
   
Please give your code if still not working.
csupriya at 23-Nov-10 8:16am
   
<asp:TextBox ID="TextBox3" runat="server" Width="177px"
ontextchanged="TextBox3_TextChanged" Height="16px"
style="margin-left: 5px"></asp:TextBox>
 

protected void Button11_Click(object sender, EventArgs e)
{
Panel1.Visible = false;
DropDownList5.ClearSelection();
TextBox3.Text = string.Empty;

}
Slacker007 at 23-Nov-10 8:18am
   
@csupriya
Stop making your comments like that (see above). If that is your answer then make it an Answer to the question.
Manfred R. Bihy at 12-Aug-11 10:58am
   
No text speak please! Read the FAQ.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

How to clear textbox not using this
textbox.text=string.empty, textbox.text=""
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 13

Hiiiiiiiiiiii,
 
Textbox1.text="";
  Permalink  
Comments
Manfred R. Bihy at 12-Aug-11 10:59am
   
The letter i seems to be stuck on your keyboard, do something about it.
shamna sankar at 16-Aug-11 1:03am
   
what you mean?
Marcus Kramer at 16-Aug-11 14:20pm
   
Read all the other answers before putting your own down. The point here is not to provide answers that already exist, but only to answer with information that has not yet been provided.
Tarun.K.S at 16-Aug-11 14:23pm
   
What Manfred meant to say is, a simple Hi with one "i" is enough. And avoid using trailing dots like this ".....". Use the <pre> tags to wrap your code, its more readable. Also avoid saying "u", "y" instead of you and why, its called text speak and is not at all tolerated, atleast here. Keep these things in mind, it will help you in the long run.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Aug 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100