This is a migrated thread and some comments may be shown as answers.

Weird Validation Issues

3 Answers 52 Views
Input
This is a migrated thread and some comments may be shown as answers.
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
DoomerDGR8 asked on 04 Nov 2010, 11:21 AM
I followed the .NET 3.5 - LinqToSql Manual CRUD Operations to implement a quick add/update functionality to my manual Manager Screen. The example uses NumericTextBoxSetting to show how validation is being handled etc. My requirement has mostly to do with text and phone numbers with RegExp patterns.

What happens is that in runtime, if there is invalid data in fileds, the scree just flickers. No error/empty messages appear. No icon appears.

Also, I have one GridDropDownColumn. How am I to extract its value while Inserting or updating?

The RadGrid and it's RadInputManager:
<fieldset id="fieldGrid" style="width: 870px">
    <legend>Managers</legend>
    <telerik:RadGrid ID="RadGridManagers" runat="server" AutoGenerateColumns="False" AllowPaging="True" GridLines="None" Width="100%" Skin="Office2007" SkinID="RadGrid_UnPageable" PageSize="20" OnNeedDataSource="RadGridManagers_NeedDataSource" OnItemCreated="RadGridManagers_ItemCreated" OnInsertCommand="RadGridManagers_InsertCommand" OnUpdateCommand="RadGridManagers_UpdateCommand" DataSourceID="LinqDataSourceManagers">
        <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" Width="100%" DataSourceID="LinqDataSourceManagers" DataKeyNames="OID" InsertItemPageIndexAction="ShowItemOnCurrentPage">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="ColumnEditCommand" ItemStyle-CssClass="MyImageButton" />
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" UniqueName="ColumnFirstName" Visible="false" />
                <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" UniqueName="ColumnLastName" Visible="false" />
                <telerik:GridTemplateColumn HeaderText="Name" UniqueName="columnName" ReadOnly="true">
                    <ItemTemplate>
                        <%# string.Format("{0} {1}", Eval("FirstName"), Eval("LastName"))%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="NickName" HeaderText="Nick Name" UniqueName="ColumnNickName" />
                <telerik:GridDropDownColumn DataField="OID" HeaderText="Pharmacy" UniqueName="ColumnPharmacy" DataSourceID="LinqDataSourcePharmacies" ListValueField="OID" ListTextField="Name" ColumnEditorID="GridDropDownColumnEditorPharmacy" />
                <telerik:GridBoundColumn DataField="PhoneNumber" HeaderText="Phone #" UniqueName="ColumnPhoneNumber" />
                <telerik:GridBoundColumn DataField="MobileNumber" HeaderText="Mobile #" UniqueName="ColumnMobileNumber" />
                <telerik:GridBoundColumn DataField="Email" HeaderText="Email Address" UniqueName="ColumnEmail" />
                <%--
                <telerik:GridButtonColumn ConfirmText="Delete this manager?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="ColumnDelete">
                    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                </telerik:GridButtonColumn>
                --%>
            </Columns>
            <EditFormSettings CaptionDataField="FirstName" CaptionFormatString="Edit Manager {0}">
                <EditColumn ButtonType="ImageButton" UniqueName="ColumnEditCommandE" />
                <FormTableItemStyle Wrap="False" />
                <FormCaptionStyle CssClass="EditFormHeader" />
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White" Width="100%" />
                <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                <FormTableAlternatingItemStyle Wrap="False" />
                <FormTableButtonRowStyle />
            </EditFormSettings>
            <CommandItemSettings ShowRefreshButton="true" ShowAddNewRecordButton="true" ShowExportToWordButton="false" ShowExportToExcelButton="true" ShowExportToPdfButton="true" ShowExportToCsvButton="true" />
            <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" Position="Bottom" />
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnRowDblClick="RadGridManagers_OnRowDblClick" />
            <Scrolling UseStaticHeaders="True" />
        </ClientSettings>
        <ExportSettings HideStructureColumns="false" FileName="PharmacyManagers" IgnorePaging="True">
            <Excel Format="ExcelML" />
            <Csv ColumnDelimiter="VerticalBar" />
        </ExportSettings>
    </telerik:RadGrid>
    <telerik:GridDropDownListColumnEditor ID="GridDropDownColumnEditorPharmacy" runat="server" DropDownStyle-Width="228px" />
    <telerik:RadInputManager runat="server" ID="RadInputManagerManagers" Enabled="true">
        <telerik:TextBoxSetting BehaviorID="TextBoxSettingNameFirst" EmptyMessage="Please enter a first name" />
        <telerik:TextBoxSetting BehaviorID="TextBoxSettingNameLast" EmptyMessage="Please enter a last name" />
        <telerik:TextBoxSetting BehaviorID="TextBoxSettingNameNick" EmptyMessage="Please enter a nick name" />
        <telerik:RegExpTextBoxSetting BehaviorID="RegExpTextBoxSettingPhone" ErrorMessage="Invalid U.K. Phone Number" ValidationExpression="^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$ " />
        <telerik:RegExpTextBoxSetting BehaviorID="RegExpTextBoxSettingMobile" ErrorMessage="Invalid U.K. Mobile Number" ValidationExpression="^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$" />
        <telerik:RegExpTextBoxSetting BehaviorID="RegExpTextBoxSettingEmail" ErrorMessage="Enter a valid email address" ValidationExpression="^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$" />
    </telerik:RadInputManager>
</fieldset>

The code-behind relating to the InputManager:
private void ShowErrorMessage() {
    RadAjaxManager manager = RadAjaxManager.GetCurrent(this.Page);
    manager.ResponseScripts.Add("window.radalert(\"Please enter valid data!\")");
}
 
private void SetupInputManager(GridEditableItem editableItem) {
    InputSetting inputSetting;
 
    // style first name
    var textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnFirstName")).TextBoxControl;
    textBox.ID = "TextBoxFirstName";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("TextBoxSettingNameFirst");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
    inputSetting.Validation.IsRequired = true;
 
    // style last name
    textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnLastName")).TextBoxControl;
    textBox.ID = "TextBoxLastName";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("TextBoxSettingNameLast");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
    inputSetting.Validation.IsRequired = true;
 
    // style nick name
    textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnNickName")).TextBoxControl;
    textBox.ID = "TextBoxNickName";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("TextBoxSettingNameNick");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
 
    // style phone number
    textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnPhoneNumber")).TextBoxControl;
    textBox.ID = "TextBoxPhoneNumber";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("RegExpTextBoxSettingPhone");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
 
    // style mobile number
    textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnMobileNumber")).TextBoxControl;
    textBox.ID = "TextBoxMobileNumber";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("RegExpTextBoxSettingMobile");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
 
    // style email
    textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor("ColumnMobileNumber")).TextBoxControl;
    textBox.ID = "TextBoxEmail";
    inputSetting = RadInputManagerManagers.GetSettingByBehaviorID("RegExpTextBoxSettingEmail");
    inputSetting.InitializeOnClient = true;
    inputSetting.TargetControls.Add(new TargetInput(textBox.UniqueID, true));
}

The code-behind relating to the RadGrid:
#region Grid Related
protected void RadGridManagers_NeedDataSource(object source, GridNeedDataSourceEventArgs e) {
    RadGridManagers.DataSource = LinqDataSourceManagers;
}
 
protected void RadGridManagers_ItemCreated(object sender, GridItemEventArgs e) {
    if (e.Item is GridEditableItem && (e.Item.IsInEditMode)) {
        GridEditableItem editableItem = (GridEditableItem)e.Item;
        SetupInputManager(editableItem);
    }
}
 
protected void RadGridManagers_UpdateCommand(object source, GridCommandEventArgs e) {
    var editableItem = ((GridEditableItem)e.Item);
    var editManagerID = (long)editableItem.GetDataKeyValue("OID");
 
    //retrieve entity form the Db
    var editManager = DbContext.Managers.Where(maan => maan.OID == editManagerID).FirstOrDefault();
    if (editManager != null) {
        try {
            //update entity's state
            editableItem.UpdateValues(editManager);
 
            //submit changes to Db
            DbContext.SubmitChanges();
 
        } catch (Exception) {
            ShowErrorMessage();
 
        }
    }
}
 
protected void RadGridManagers_InsertCommand(object source, GridCommandEventArgs e) {
    var editableItem = ((GridEditableItem)e.Item);
 
    //extract properties
    Hashtable values = new Hashtable( );
    editableItem.ExtractValues(values);
 
    //create new entity
    Manager newManager = new Manager() {
        FirstName = (string)values["FirstName"] ?? String.Empty,
        LastName = (string)values["LastName"] ?? String.Empty,
        NickName = (string)values["NickName"] ?? String.Empty,
        PhoneNumber = (string)values["PhoneNumber"] ?? String.Empty,
        MobileNumber = (string)values["MobileNumber"] ?? String.Empty,
        Email = (string)values["Email"] ?? String.Empty
    };
 
    DbContext.Managers.InsertOnSubmit(newManager);
 
    try {
        //submit changes to Db
        DbContext.SubmitChanges();
    } catch (Exception) {
        ShowErrorMessage();
    }
}
#endregion

I'm missing something here right? Have I hooked up everything right? This is a Content Page and the ShowErrorMessage() first traces-out the parent's WindowManager.

Any pointer please... this was suppose to be a simple screen and I have like 7 others to do today. Thank you.

*EDIT*

Also, using Firefox + FireBug, I see a warning whenever I interact with the grid I mentioned above. Attached.

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 05 Nov 2010, 03:17 PM
Hello Hassan,

To answer question about accessing the value from the GridDropDownColumn, you do it the same way as you access the other columns. It's part of the Hashtable values.
0
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 05 Nov 2010, 03:29 PM
Thanks Cori. Actually, the Pharmacy ID that I'm looking for in the hashtable ain't there. You see, InputManager is handling all the fields except the Dropdown. The Dropdown is separately handler by a GridDropdwonColumnEditor working lonely. I don't know if this combination will work or not. It's currently not.
0
Iana Tsolova
Telerik team
answered on 10 Nov 2010, 02:45 PM
Hi Hassan,

Basically you can have whatever combination of columns in the grid and all the different fields you like in the edit form. However going through you code I observed that the DataField of the GridDropDownColumn is data key filed the same time. And if the OID is auto generated from the database when new record is added, it is rather expected that it is not present in the hashtable with the new values.
Regarding the issue with the validation of the RadInputManager: Could you please try replacing the GridBoundColumns with GridTemplateColumns having ASP:TextBox controls in the EditTemplate and let me know if it works thus?

Greetings,
Iana
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Input
Asked by
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Cori
Top achievements
Rank 2
DoomerDGR8
Top achievements
Rank 2
Iron
Iron
Veteran
Iana Tsolova
Telerik team
Share this question
or