I'm using a RadButton inside a RadListView with ItemTemplate. The button is supposed to cause a post-back (handled by the ItemCommand of the RadListView) if a value in a RadTextBox is present, otherwise just display the RequiredFieldValidator/ValidationSummary info.
I've got it working to the point where it will validate the field (it pops the RequiredFieldValidator message as per the instructions in the ValidationSummary control), however regardless of whether or not the validator fires, it still does the postback and fires the ItemCommand handler.
html:
Just to verify to you that I'm setting the ValidationGroup for all controls involved (it is being set in code in the ItemDataBound handler):
Any ideas? I'm going to handle this server-side (I'll test the text box and if it's blank I'll set the toggle of the button back to unchecked) but I'd really like the standard asp controls to handle it so no post-back happens unless it needs to.
Thanks
-
Scott
I've got it working to the point where it will validate the field (it pops the RequiredFieldValidator message as per the instructions in the ValidationSummary control), however regardless of whether or not the validator fires, it still does the postback and fires the ItemCommand handler.
html:
<telerik:RadListView ID="lstCommissions" runat="server" DataKeyNames="EmployeeCommissionBankID" ItemPlaceholderID="plhCommissions" OnItemCommand="lstCommissions_ItemCommand" OnItemDataBound="lstCommissions_ItemDataBound" OnNeedDataSource="lstCommissions_NeedDataSource"> <LayoutTemplate> <div class="CommissionControlContainer"> <div class="LoanNumberTitle">Loan Number</div> <div class="CommissionTotalTitle">Commission</div> <div class="SpreadTitle">Commission Spread</div> <asp:PlaceHolder ID="plhCommissions" runat="server" /> </div> </LayoutTemplate> <ItemTemplate> <div class="RowContainer"> <div class="LoanNumber"><asp:Label ID="lblLoanNumber" runat="server" /></div> <div class="CommissionTotal"><asp:Label ID="lblCommissionTotal" runat="server" /></div> <div class="SpreadButton"> <telerik:RadButton ID="btnSplit" runat="server" AutoPostBack="true" ButtonType="ToggleButton" CausesValidation="true" CommandName="Split" CommandArgument='<% Bind("LoanNumber"); %>' Style="padding-left: 25px;" ToggleType="CheckBox" > <ToggleStates> <telerik:RadButtonToggleState PrimaryIconCssClass="rbRemove" Text="Remove Spread" /> <telerik:RadButtonToggleState PrimaryIconCssClass="rbOk" Text="Spread" /> </ToggleStates> </telerik:RadButton> </div> <div class="SpreadValue"> <telerik:RadNumericTextBox ID="txtSpreadAmount" runat="server" AutoPostBack="true" /> <asp:RequiredFieldValidator ID="rfvSpreadAmount" runat="server" ControlToValidate="txtSpreadAmount" ErrorMessage="Spread amount is required" Text="*" /> <asp:ValidationSummary ID="vsSpreadAmount" runat="server" DisplayMode="BulletList" ShowMessageBox="true" ShowSummary="false" Visible="true" /> </div> </div> </ItemTemplate> </telerik:RadListView>Just to verify to you that I'm setting the ValidationGroup for all controls involved (it is being set in code in the ItemDataBound handler):
if (e.Item is RadListViewDataItem) { RadListViewDataItem item = e.Item as RadListViewDataItem; // item-level objects Label lblLoanNumber = item.FindControl("lblLoanNumber") as Label; Label lblCommissionTotal = item.FindControl("lblCommissionTotal") as Label; RadNumericTextBox txtSpreadAmount = item.FindControl("txtSpreadAmount") as RadNumericTextBox; RadButton btnSplit = item.FindControl("btnSplit") as RadButton; RequiredFieldValidator rfvSpreadAmount = item.FindControl("rfvSpreadAmount") as RequiredFieldValidator; ValidationSummary vsSpreadAmount = item.FindControl("vsSpreadAmount") as ValidationSummary; EmployeeCommissionEntity ec = item.DataItem as EmployeeCommissionEntity; if (ec.Amount.HasValue) { // set the validation groups for all the controls that need it btnSplit.ValidationGroup = txtSpreadAmount.ValidationGroup = rfvSpreadAmount.ValidationGroup = vsSpreadAmount.ValidationGroup = "Split_" + ec.EmployeeCommissionBankID.ToString().Replace("-", string.Empty); lblLoanNumber.Text = ec.LoanNumber; lblCommissionTotal.Text = string.Format("{0:c}", ec.Amount); txtSpreadAmount.MaxValue = ec.Amount.Value.ToDouble(); txtSpreadAmount.MinValue = 0; } else item.Visible = false; } Any ideas? I'm going to handle this server-side (I'll test the text box and if it's blank I'll set the toggle of the button back to unchecked) but I'd really like the standard asp controls to handle it so no post-back happens unless it needs to.
Thanks
-
Scott