Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
XML
<asp:TextBox ID="TextBox3" runat="server" Width="177px" ontextchanged="TextBox3_TextChanged" Height="16px" style="margin-left: 5px"></asp:TextBox> 


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

[/Edit]
Posted
Updated 23-Nov-10 22:19pm
v5
Comments
fjdiewornncalwe 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 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;

}
fjdiewornncalwe 23-Nov-10 10:52am    
What is happening in your ontextchanged handler? It may be part of the issue.
Dalek Dave 24-Nov-10 4:19am    
Edited for Grammar and Spelling.

:) Txtbxclearfilesafter.Clear(); :)

in place of txtbxclearfileafter write the name of ur textbox.......
 
Share this answer
 
v4
Comments
csupriya 23-Nov-10 7:54am    
ok..in place of txtbxclearfileafter i wrote textbox3..but the intellisense doesnt give me clear()...:S
sujeet101 23-Nov-10 7:58am    
where u write the code ?
can u send the code?
csupriya 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 24-Nov-10 4:19am    
Good Answer.
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

C#
protected void Button1_Click(object sender, EventArgs e)
 {
     TextBox1.Text = String.Empty;
     TextBox2.Text = String.Empty;
 }



HTML Code

XML
<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....
 
Share this answer
 
Comments
Ankur\m/ 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??
protected void Button1_Click(object sender, EventArgs e) 
{
Textbox1.Text="";//this for clear the text box
DropDownList1.ClearSelection();
}//this for clear thr dropdownlist  
 
Share this answer
 
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.
 
Share this answer
 
you will find it over here
 
Share this answer
 
Hi, Use normal html reset control for clearing textbox values in client side.
 
Share this answer
 
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?
 
Share this answer
 
Comments
csupriya 23-Nov-10 7:55am    
i have called it in button_click event..
Mohd Wasif 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 23-Nov-10 8:04am    
Please give your code if still not working.
csupriya 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 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.
How to clear textbox not using this
textbox.text=string.empty, textbox.text=""
 
Share this answer
 
Hiiiiiiiiiiii,

Textbox1.text="";
 
Share this answer
 
Comments
Manfred Rudolf Bihy 12-Aug-11 10:59am    
The letter i seems to be stuck on your keyboard, do something about it.
Ashika s 16-Aug-11 1:03am    
what you mean?
fjdiewornncalwe 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900