Pankouri
Pankouri

Reputation: 676

How can I execute some line of code when I click a link in a aspx page?

My solution for one problem has created a new problem for me. In my page, I have some required field validation. At first I had close button which redirects me to another page. since. Since this button only redirects met to another page so I replace it with a link. previous code

My replaced code,

That works fine for me. Now you may want to know why I did that. I did that because the client side required field validation (RFV) was preventing me to redirect the page. So I had to do that. But, for the add button, I need to redirect the same page skipping, again the RFV is preventing me. Now 1 solution can be use the link instead of button. which is creating another problem. button a click event where I can execute some lines of code. since the link doesn't have the click event, how can I achieve this goal. both solution is accepted, either button click that can skip the RFV or clicking on link, execution some lines of code, the lines of code that I want to execute is that

 protected void btnAdd_Click(object sender, ImageClickEventArgs e)
    {
        //DisableButtons();
        CLearControls();
        btnAdd.Enabled = true;
        btnSave.Enabled = true;
    }

Can Anyone help me from this tricky problem? thanx in advance.

Upvotes: 0

Views: 86

Answers (1)

Muhammad Akhtar
Muhammad Akhtar

Reputation: 52241

Just set CausesValidation="false" in your linkbutton. Your required Field Validator will not stop it from working.

 <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false"></asp:LinkButton>

Upvotes: 1

Related Questions