• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 483
  • Last Modified:

Validation control and LinkButton control problem

I have Validation control that validates user input on TextBox control.
Also there is LinkButton on my form with OnClick event handler defined.

Now when LinkButton is clicked and Validation condition is not met then OnClick handler of LinkButton is not invoked.

Why is this happening?
How does the Validation ctrl. suppreses OnClick event of LinkButton ctrl?

When Validation condition on TextBox is OK then all works as expected.

Here is page to illustrate this:

<%@ Page Language="C#" %>
<script Language="C#" runat="server">

    protected void LinkButton1_Click(object sender, EventArgs e)
        int x = 1;

<html >
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton></div>

This code does not do anything smart, it is just for testing.
Try putting breakpoint on line "int x = 1;" to see this behavior.
1 Solution
Hamed ZaghaghiProgrammerCommented:
you can set the CauseValidation of tyhe link button to False
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now