Dmase05
Dmase05

Reputation: 1089

ASP Hyperlink control using href="#" and validation

I'm having an issue using the asp hyperlink control and the "#" href value. I don't want the link to navigate away from the current page or reload it but I want the link to cause validation to happen to a specific validation group.

The following line doesn't trigger validation.

<asp:HyperLink id="next" runat="server" CausesValidation="true" ValidationGroup="SideRifStepOne" href="#">Next Step</asp:HyperLink>

If I use the same attributes for the validation works but the page is reloaded. Any suggestions for triggering validation without reloading the page?

Thanks

Upvotes: 2

Views: 4202

Answers (3)

Chandu
Chandu

Reputation: 82933

Another solution would be calling Page_ClientValidate() manually:

<asp:HyperLink id="next" runat="server" href="javascript:doValidate()">Next Step</asp:HyperLink> 
                <script type="text/javascript">
                    function doValidate()
                    {
                        Page_ClientValidate();
                    }
                </script>

Upvotes: 3

Mikael Svenson
Mikael Svenson

Reputation: 39695

You could add EnableClientScript="true" to your validation control. By doing this the validation will be performed in javascript before a postback occurs.

Upvotes: 0

Letseatlunch
Letseatlunch

Reputation: 2487

have you tryed using a linkbutton? you can set onclientclick="return false;" to prevent a postback and it should cause the validation

Upvotes: 1

Related Questions