views:

122

answers:

3

hi,
I have an label "test" comimg from .cs [c# code] text="data saved successfully" . but once I click the save button i need to clear its text right now I have 3 required field validators. with message [cannot be blank, cannot be blank,cannot be blank,] as user as clicked the save button I need to clear the text of the label. But need to show the required fields validator message

any idea how to solve it

thank you

+1  A: 

On the client-side use a script like this

<script type="text/javascript">
  function clearLabelValue(){
     var labelObj = document.getElementById("<%= myLabel.ClientID %>");
     labelObj.value = "";
  }
</script>

<asp:Label id="myLabel" runat="server" Text="Some text"/>
<asp:Button id="myButton" runat="server" Text="Submit" OnClientClick="clearLabelValue();return false;"/>

Didn't test it in detail, but should work.

It is not really clear what you want to achieve, although I have the feeling there may be a "better" (more standard compliant) way of achieving what you want. Maybe you could describe more clearly what you want, so we may be able to help you.

Juri
A: 

In these situations when a particular button has validation attached to it and also we need to fire some javascript what is done is to define a javascript function which is called on click of save button.

What this javascript function does:

This function will take your label and will set its value as blank so that the text is cleared.

Now in order to validate the page which happens internally (in case the javascript function is not written on the save button click) we need to explicitly call what asp.net call for client side validation.

There is a function page_ClientValidate which needs to be called from this javascript function so that validation is still done and we also do some other processing like clearing the label in this case.

Beginner
A: 

make a javascript function like:

<Script type="text/javascript">
function clearText(cntId) {
  var cnt = document.getElementById(cntId);
  cnt.value ="";
  return false;
}
</script>

then on your submit button attach a client side event

<asp:Button id='btnSubmit' Text='Submit' onClientClick='clearText("<%this.lblLable.ClientId%>");' .... />
S M Kamran
In this case will the Page Validation takes place, say there are three text boxes which are to be validated on the click of Save Button? Thanks.
Beginner
Yes... The page validation will work as usual. The validations are invoked from with in the Click event handler.
S M Kamran