1

I am using Page.Isvalid function in my web page.I have two buttons in my web page namely "save" and "generate".when i click the save button the validation summary will be invoked in which all the validations in this page will be shown.

Now I dont want to show a particular validation message for the "Save" button, but the same validation message should be shown specifically to "generate" button in the same page.

But i am using Page.Isvalid in the "save" button click which is displaying all the validation messages in the page.

Any help would be deeply appreciated.Thanks

3 Answers 3

2

You can use ValidationGroup(s) to do this.

<form id="form1" runat="server">
   <div>
       <asp:TextBox ID="TextBox1" runat="server" />
       <asp:RequiredFieldValidator ID="R1" runat="server" 
            ErrorMessage="*" 
            ValidationGroup="GenerateOnly"
            ControlToValidate="TextBox1" />
       <asp:Button ID="Generate" runat="server" Text="Generate"
            ValidationGroup="GenerateOnly" />
       <asp:Button ID="Save" runat="server" Text="Save" />
   </div>
</form>

This example triggers the validator if Generate is clicked, but not when Save is clicked, and also works when calling Page.IsValid in the buttons onclick function.

Sign up to request clarification or add additional context in comments.

Comments

2

not entirely sure what you mean but here goes. If you want both the save and generate buttons to generate validation messages then why not move the Page.Isvalid along with the validation code into another method. Call this method from both the save and generate methods.

If I've got the wrong end of the stick please let me know a bit more. Cheers Tigger

Comments

2

Ya buddy if you have to call the same function for two different buttons it is not possible without the concept of overloading. Otherwise you have to create two methods. But I'am not sure as i am a begginer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.