3

the function in OnItemCommand of the asp:Repeater is not working randomly. It's a normal one coded like this.

<asp:Repeater runat="server" ID="control01" OnItemCommand="control01_OnItemCommand"> <ItemTemplate> <li><asp:LinkButton runat="server" ID="btn_button" CommandArgument='1'>Click</asp:LinkButton></li> </ItemTemplate> </asp:Repeater> 

After some time spent on debug I found it's related a input text box on page.

<asp:TextBox ID="txt_input" runat="server"></asp:TextBox>

Only if it's correct value (validated) the function works well.

If I remove <asp:RequiredFieldValidator> and <asp:RequiredFieldValidator> on the text box here

<asp:RegularExpressionValidator ID="rvDecimal" ControlToValidate="txt_input" runat="server" ErrorMessage="Please enter a valid value" ValidationExpression="^(-)?\d+(\.\d\d)?$"></asp:RegularExpressionValidator> <asp:RequiredFieldValidator ID="rfd_input" runat="server" ControlToValidate="txt_input" Text="Please enter a valid value"></asp:RequiredFieldValidator> 

OnItemCommand got fired and the function works well.

The question is, how can I keep the validation and make the function in OnItemCommand working?

4
  • What's ValidatorEnable($get(CONTROL_ID), true); supposed to be? Can you at least post the rest of the relevant code? Commented Jul 1, 2016 at 1:37
  • @Leo edtied the question with code and more details added. Commented Jul 1, 2016 at 1:54
  • I was actually hoping to get the ValidatorEnable($get(CONTROL_ID), true); part clarified which looks like js code. have you checked for JS errors? If there are js errors the page might not postback... Commented Jul 1, 2016 at 2:13
  • @Leo I've checked that the ValidatorEnable in jQuery is irrelevant so I just removed it. Commented Jul 1, 2016 at 2:33

2 Answers 2

1

If you want the postback to occur even when a validation fails, you can disable the client validation:

<asp:RegularExpressionValidator ID="rvDecimal" runat="server" EnableClientScript="false" ... /> <asp:RequiredFieldValidator ID="rfd_input" runat="server" EnableClientScript="false" ... /> 

If you want to see an indicator besides each field, showing that its data is not valid, then the validators should have a Text property.

On the other hand, if you want a list of failed validations, you can add a ValidationSummary to the page and an ErrorMessage to each validator.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks that sounds like a solution. However for my case, I would like to keep the validation for other controls in my page, while skipping this only in the particular control LinkButton.
1

Finally I've solved the problem by adding CausesValidation="false" in the control.

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

This would skip the validation the trigger the function in OnItemCommand

1 Comment

Cheers, very handy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.