Hi All,
Been a little while but I'm doing UI work again, and fixing some bugs. I am up against a wall on this one. Essentially, I need to have a dual-validation - if a checkbox is checked <t:GridCheckBoxColumn...> then I need to perform both a regexp validator for e-mail address format and a custom validator to make sure it is not blank if the checkbox is checked. This occurs in a <t:GridTemplateColumn><EditItemTemplate>
I would first of all like to know if I can get the actual row being edited out of the arguments passed to the validator - it seems not. If that is not possible, an index to the row being edited will do - where can I get that? Maybe there is a way to do a FindControl() on a row? Finally, I am willing to iterate all rows if I must and ask "are you being edited?" (assuming that I can.)
I can get the *old* values of the columns using getDataKey(), in my validator JavaScript, but I don't know how to get the new value of the checkbox.checked or the TextBox.value.
Here is the markup for the columns of interest:
And the related JavaScript function:
Thanks for any ideas you can offer!
Tim
Been a little while but I'm doing UI work again, and fixing some bugs. I am up against a wall on this one. Essentially, I need to have a dual-validation - if a checkbox is checked <t:GridCheckBoxColumn...> then I need to perform both a regexp validator for e-mail address format and a custom validator to make sure it is not blank if the checkbox is checked. This occurs in a <t:GridTemplateColumn><EditItemTemplate>
I would first of all like to know if I can get the actual row being edited out of the arguments passed to the validator - it seems not. If that is not possible, an index to the row being edited will do - where can I get that? Maybe there is a way to do a FindControl() on a row? Finally, I am willing to iterate all rows if I must and ask "are you being edited?" (assuming that I can.)
I can get the *old* values of the columns using getDataKey(), in my validator JavaScript, but I don't know how to get the new value of the checkbox.checked or the TextBox.value.
Here is the markup for the columns of interest:
| <telerik:GridCheckBoxColumn DataField="SendNotification" |
| DataType="System.Boolean" |
| meta:resourcekey="GridCheckBoxColumnResource1" |
| SortExpression="SendNotification" |
| UniqueName="SendNotification"> |
| </telerik:GridCheckBoxColumn> |
| <telerik:GridTemplateColumn DataField="NotificationAddress" |
| meta:resourcekey="GridTemplateColumnResource11" |
| SortExpression="NotificationAddress" UniqueName="NotificationAddress"> |
| <EditItemTemplate> |
| <asp:TextBox ID="NotificationAddressTextBox" runat="server" |
| CausesValidation="True" |
| meta:resourcekey="NotificationAddressTextBoxResource1" |
| Text='<%# Bind("NotificationAddress") %>' MaxLength="1024"> |
| </asp:TextBox> |
| <asp:RegularExpressionValidator ID="NotificationAddressTextBoxValidator" |
| runat="server" ControlToValidate="NotificationAddressTextBox" |
| CssClass="ValidationError" Display="Dynamic" |
| ErrorMessage="Invalid e-mail address" |
| meta:resourcekey="NotificationAddressTextBoxValidatorResource1" |
| ValidationExpression="..."> |
| </asp:RegularExpressionValidator> |
| <asp:CustomValidator runat="server" ID="SendNotificationToValidator" |
| EnableClientScript="true" |
| ControlToValidate="NotificationAddressTextBox" |
| ClientValidationFunction="CheckEmailRequired" |
| Display="Dynamic" ErrorMessage="e-mail address required." |
| ValidateEmptyText="true" /> |
| </EditItemTemplate> |
| <ItemTemplate> |
| <%# Eval("NotificationAddress") %> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
And the related JavaScript function:
| function CheckEmailRequired(source, args) { |
| var grid = $find("<%=AlertConfigurationRadGrid.ClientID %>"); |
| var MasterTable = grid.get_masterTableView(); |
| // Can I get the row or item from source or args? |
| var selectedRows = MasterTable.get_dataItems(); |
| // Can I ask each row if it is being edited? |
| for (var i = 0; i < selectedRows.length; i++) { |
| var row = selectedRows[i]; |
| var oldSendNotification = row.getDataKeyValue("SendNotification"); |
| var oldNotificationAddress = row.getDataKeyValue("NotificationAddress"); |
| } |
| args.IsValid = true; |
| return; |
| } |
Thanks for any ideas you can offer!
Tim