clearing elemets that don't post back

inzo21

Regular
Joined
Nov 5, 2003
Messages
74
Hello all,

Okay - problem of the day. Here goes.

I created an input form with server side controls and vaildation controls on it. There are two web form (not html) buttons - submit and clear.

Now, when the vaildation controls are challenged, the clear button code does not function - as it executes on the server and the validation controls are client side based.

I'm calling the clear on the button_Click event as follows:

field.text = ""

I tried using Javascript with a similiar function:

<script language="javascript">
function clearfields()
field.text = ""
</script>

and called it on the onClick event of the button (i.e. onClick"clearfields()"

It couldn't recognize the function in the ascx file.

Does anyone have a solution to clearing the text / value of server side controls (text and labels) that is client side based? I think it can be done - but I stuck again.

thanx in advance?

inzo
 
I tried that one before but double checked it now- it's still the same effect. The form won't reset after it has been validated.

thanks for the reply.

inzo
 
Hey Kahlua,

Same effect regardless of the button type I use. I tried a submit button, an HTML button, and ASP button - all had the same effect which is to say that they all clear the form prior to validation but will not clear it after it has been validated.

still looking -)

inzo
 
After a successful validation, and the values have been posted back to the server, the input field then looks like
<input name="txtTest" type="text" value="myValue" id="txtTest" />

The value is now an attribute of the input field, so the rest button will not work, it only works when the value is not a default and only when it is typed but not yet committed to the field. In this case you would have to use javascript to clear the fields. That is my guess.
 
Back
Top