ANAT2403
asked on
clear textbox in clientside
in ASP.NET 2.0 I have a page with a formview and in it a textbox and a button.
I want that push on the button will clear the textbox in clientside in javascript.
If I didn't have the formview I could do something like:
<asp:TextBox ID="TBCV" runat="server" Text='<%# Bind("CV") %>'></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="this.form.T BCV.value= ''" />
but as the texbox TBCV is a part of a formview control so "this.form.TBCV.value" is wrong.
How do I have to write it?
If I do it in server side I use the findcontrol but I don't want to use it because I want it to be quicker.
How do I do it?
ThankYou
Anat
I want that push on the button will clear the textbox in clientside in javascript.
If I didn't have the formview I could do something like:
<asp:TextBox ID="TBCV" runat="server" Text='<%# Bind("CV") %>'></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="this.form.T
but as the texbox TBCV is a part of a formview control so "this.form.TBCV.value" is wrong.
How do I have to write it?
If I do it in server side I use the findcontrol but I don't want to use it because I want it to be quicker.
How do I do it?
ThankYou
Anat
ASKER
Hi,
You did not react to the fact that I am having a formview. In formview you can not turn to the control directly
but through the formview.
To what you wrote in the code behind I know how to change and it should be:
Button tempTB = (Button)FormView1.FindCont rol("TBCV' ");
and then
tempTB.Attributes.Add("onc lick","jav ascript:Cl earIT('CV_ containerT B')");
but to the javascript function - this is my problem how to write.
By the way if I do what you said I get the error:
A Runtime Error
Error: 'document.getElementById(. ...) is null or not an object.
You did not react to the fact that I am having a formview. In formview you can not turn to the control directly
but through the formview.
To what you wrote in the code behind I know how to change and it should be:
Button tempTB = (Button)FormView1.FindCont
and then
tempTB.Attributes.Add("onc
but to the javascript function - this is my problem how to write.
By the way if I do what you said I get the error:
A Runtime Error
Error: 'document.getElementById(.
ASKER
Sorry but my comment was sent before I finished writing:
Ignore it.
Again
Hi,
You did not react to the fact that I am having a formview. In formview you can not turn to the control directly
but through the formview.
To what you wrote in the code behind I know how to change and it should be:
Button tempTB = (Button)FormView1.FindCont rol("Butto n2");
and then
tempTB.Attributes.Add("onc lick","jav ascript:Cl earIT('TBC V');
but to the javascript function - this is my problem how to write.
By the way if I do what you said I get the error:
A Runtime Error
Error: 'document.getElementById(. ...) is null or not an object.
ThankYou
Anat
Ignore it.
Again
Hi,
You did not react to the fact that I am having a formview. In formview you can not turn to the control directly
but through the formview.
To what you wrote in the code behind I know how to change and it should be:
Button tempTB = (Button)FormView1.FindCont
and then
tempTB.Attributes.Add("onc
but to the javascript function - this is my problem how to write.
By the way if I do what you said I get the error:
A Runtime Error
Error: 'document.getElementById(.
ThankYou
Anat
Try this
Me.Button2.Attributes.Add( "onClick", "javascript:ClearIT('" & Me.Txt1.ClientID & "')")
Me.Button2.Attributes.Add(
ignore the last post, I dont think it will work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just Perfect !!!!
ThankYou
I add here the code in C# if anybody needs it.
TextBox TBCV = (TextBox)FVSelfEntry.FindC ontrol("CV _container TB");
Button btnClear = (Button)FVSelfEntry.FindCo ntrol("Btn ClearCV");
btnClear.Attributes.Add("o nclick", "javascript:ClearIT('" + TBCV.ClientID + "')");
ThankYou
I add here the code in C# if anybody needs it.
TextBox TBCV = (TextBox)FVSelfEntry.FindC
Button btnClear = (Button)FVSelfEntry.FindCo
btnClear.Attributes.Add("o
I am glad its working for you.
Dont forget to answer this question please so others can use it
Good Luck
Dont forget to answer this question please so others can use it
Good Luck
ASKER
terribly sorry. I accepted the answer before but somehow it didn't catch.
Anat.
Anat.
Thats Ok Anat :-)
ASKER
Hi sammy
It is working for me the clear textbox but again it refreshes the screen and I don't know why?
Can you help?
Anat
It is working for me the clear textbox but again it refreshes the screen and I don't know why?
Can you help?
Anat
add this script to the head of your aspx page
<script type="text/javascript">
function ClearIT(txtID)
<!--
{
document.getElementById(tx
}
// -->
</script>
and in your code behind page load add this
Me.Button2.Attributes.Add(
HTH