开发者

validation problem in asp.net

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 i开发者_Go百科n 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


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜