kcwallace Posted August 11, 2005 Posted August 11, 2005 I need to write code that will, for example, clear a textbox but not reload the page. It is my understanding that you need to use Javascript for this. If so, how? Quote Go Beavs!!!
*Experts* Bucky Posted August 11, 2005 *Experts* Posted August 11, 2005 I'd reccomend scanning through some info about Javascript, but the property you're looking for can be found here. This will go inside your <head> tag. This simply makes a function ClearTextBox() that you can call from any <script> block following it. <script type="text/javascript"> function ClearTextbox() { myTextBox.value = ""; // Clear the textbox, where myTextBox is the name } </script> And here is an example of the textbox control you'd use, and the button which would clear it. <input type="text" name="myTextBox" /> <input type="button" value="Clear" onClick="javascript:ClearTextBox()" /> This is untested code, but you should not have any issues. It is pretty straightforward. Just remember to replace myTextBox with the actual name of the input field. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Joe Mamma Posted August 11, 2005 Posted August 11, 2005 or simply: <input type="text" name="myTextBox" /> <input type="button" value="Clear" onClick="javascript:document.all.myTextBox.value=''" /> Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
kcwallace Posted August 11, 2005 Author Posted August 11, 2005 All the examples I have seen only apply to HTML controls. Is there a method that works with ASP Controls? Quote Go Beavs!!!
*Experts* Bucky Posted August 11, 2005 *Experts* Posted August 11, 2005 As far as JavaScript is concerned, after the ASP.NET server renders the web page, the controls actually become standard HTML input controls. Since JavaScript is run on the client side, and the only thing the client receives are HTML controls, this code will work. Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.