views:

35

answers:

3

Hi all, 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

+1  A: 

Hi, 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

Tigger
Thanks for the suggestion tigger.
jithin
+2  A: 

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.

Willem
excellent willem :) thanks..
jithin
+1  A: 

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

Prateek
thanks pratheek.
jithin