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

Very Strange error when returning from postback

3 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 08 Aug 2012, 11:15 AM
Hi

I dont know If this has been asked before. Did not see the same occurance.

I have a RadGrid that is populated with the NeedDataSource property which gets a list of Items from the Database. These records are all Identical at first except for there ID.

The Grid works with Item GridTemplateColumns and GridBoundColumns.
Most of the Columns have Dropdownboxes for editing.
One of the dropdownboxes calls a Method from Serverside to determine if Input validation on another control must take place.

Here is the problem All the records work perfectly eccept for the 2nd record.
When ever I change the value I can no longer Change the field that is being validated and no postbacks can be preformed because of the validator.

Any Advice wood be great or a posible cause for why only the 2nd record has this problem.

Below is the Grid
<telerik:RadGrid Visible="false" ID="rgBusValidators" runat="server" AutoGenerateEditColumn="True" 
          AlternatingItemStyle-BackColor="white" GridLines="None" 
          GroupingEnabled="False" Width="100%" Height="500px"
          AutoGenerateColumns="False" 
          onneeddatasource="rgBusValidators_NeedDataSource" 
          onupdatecommand="rgBusValidators_UpdateCommand" 
    oneditcommand="rgBusValidators_EditCommand" 
    onitemcreated="rgBusValidators_ItemCreated" >
          <AlternatingItemStyle BackColor="White" />
          <MasterTableView Caption="Bus Daily Report" 
              DataKeyNames="BusNumber,Depot,Operations,ValNum,ValOp,ValFault,AllocNow,AllocDay1,AllocDay2,ValStat,ServiceNumber" 
              ShowFooter="true">
              <Columns>
                      <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" 
                      DataField="BusDailyReportID" HeaderText="BusDailyReportID" 
                      ReadOnly="true" UniqueName="BusDailyReportID" Visible="True">                      
                  </telerik:GridBoundColumn>
                      <telerik:GridBoundColumn AllowFiltering="False" AllowSorting="False" 
                      DataField="BusNumber" HeaderText="Bus Number" 
                      ReadOnly="true" UniqueName="BusNumber" Visible="true">                      
                  </telerik:GridBoundColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Depot reporting to" UniqueName="Depot" >
                      <ItemTemplate>
                          <asp:Label ID="lblDepot" runat="server" Text='<%# Eval("Depot") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                        <telerik:RadComboBox ID="Depot" runat="server"
                                AppendDataBoundItems="False"
                                SelectedValue='<%# Bind("Depot") %>'
                                DataTextField="Depot" 
                                DataValueField="Depot"
                                Width="160pt">  
                                                                
                                <Items>
                                <telerik:RadComboBoxItem Text="Midrand Depot" Value="Midrand Depot" />
                                <telerik:RadComboBoxItem Text="Pretoria Depot" Value="Pretoria Depot" />
                                </Items>
                          </telerik:RadComboBox>
                            
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
                    
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="In Operations" UniqueName="Operations" >
                      <ItemTemplate>
                          <asp:Label ID="lblOperations" runat="server" Text='<%# Eval("Operations") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="Operations" runat="server"
                                AppendDataBoundItems="false"
                                SelectedValue='<%# Bind("Operations") %>'
                                DataTextField="Operations" 
                                DataValueField="Operations"
                                Width="160pt"
                                OnSelectedIndexChanged="Operations_SelectedIndexChanged"
                                AutoPostBack="True">                                
                                <Items>
                                <telerik:RadComboBoxItem Text="Operations" Value="Operations" />
                                <telerik:RadComboBoxItem Text="Repairs" Value="Repairs" />
                                <telerik:RadComboBoxItem Text="Service" Value="Service" />
                                </Items>
                          </telerik:RadComboBox>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Validator Number" UniqueName="ValNum" >
                      <ItemTemplate>
                          <asp:Label ID="lblValNum" runat="server" Text='<%# Eval("ValNum") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="ValNum" runat="server"
                                AppendDataBoundItems="true"
                                SelectedValue='<%# Bind("ValNum") %>'
                                DataSourceID="ValidatorNumbers"
                                DataTextField="ValNum" 
                                DataValueField="ValNum"
                                Width="160pt">
                          </telerik:RadComboBox>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Validator Operational" UniqueName="ValOp" >
                      <ItemTemplate>
                          <asp:Label ID="lblValOp" runat="server" Text='<%# Eval("ValOP") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="ValOp" runat="server"
                                AppendDataBoundItems="False"
                                SelectedValue='<%# Bind("ValOp") %>'
                                DataTextField="ValOp" 
                                DataValueField="ValOp"
                                AutoPostBack="true"
                                OnSelectedIndexChanged="ValOp_SelectedIndexChanged"
                                Width="160pt">                                
                                <Items>
                                <telerik:RadComboBoxItem Text="Operational" Value="Operational" />
                                <telerik:RadComboBoxItem Text="Faulty" Value="Faulty" />
                                <telerik:RadComboBoxItem Text="Not in Operations" Value="Not in Operations" />
                                </Items>
                          </telerik:RadComboBox>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Validator Fault Type" UniqueName="ValFault" >
                      <ItemTemplate>
                          <asp:Label ID="lblValFault" runat="server" Text='<%# Eval("ValFault") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="ValFault" runat="server"
                                AppendDataBoundItems="False"
                                SelectedValue='<%# Bind("ValFault") %>'
                                DataTextField="ValFault" 
                                DataValueField="ValFault"
                                Width="160pt">                                
                                <Items>
                                <telerik:RadComboBoxItem Text="Not Applicable" Value="Not Applicable" />
                                <telerik:RadComboBoxItem Text="Validator freeze and can not scan CSC" Value="Validator freeze and can not scan CSC" />
                                <telerik:RadComboBoxItem Text="Validator reading ‘out of service’ on display screen" Value="Validator reading ‘out of service’ on display screen" />
                                <telerik:RadComboBoxItem Text="Validator Completely Off(not switching on)" Value="Validator Completely Off(not switching on)" />
                                <telerik:RadComboBoxItem Text="Validator reset lock broken" Value="Validator reset lock broken" />
                                <telerik:RadComboBoxItem Text="Validator screen not working (but still able to scan CSC)" Value="Validator screen not working (but still able to scan CSC)" />
                                </Items>
                          </telerik:RadComboBox>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Allocation for the day" UniqueName="AllocNow" >
                      <ItemTemplate>
                          <asp:Label ID="lblAllocNow" runat="server" Text='<%# Eval("AllocNow") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="AllocNow" runat="server"
                                AppendDataBoundItems="true"
                                SelectedValue='<%# Bind("AllocNow") %>'
                                DataSourceID="dsStations"
                                DataTextField="Description" DataValueField="Description"
                                Width="160pt"> 
                                <Items>
                                <telerik:RadComboBoxItem Text="Midrand Depot" Value="Midrand Depot" />
                                <telerik:RadComboBoxItem Text="Pretoria Depot" Value="Pretoria Depot" />
                                </Items>
                          </telerik:RadComboBox>
  
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Allocation Day -1" UniqueName="AllocDay1" >
                      <ItemTemplate>
                          <asp:Label ID="lblAllocDay1" runat="server" Text='<%# Eval("AllocDay1") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:Label ID="AllocDay1" runat="server" Text='<%# Eval("AllocDay1") %>'></asp:Label>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Allocation Day -2" UniqueName="AllocDay2" >
                      <ItemTemplate>
                          <asp:Label ID="lblAllocDay2" runat="server" Text='<%# Eval("AllocDay2") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <asp:Label ID="AllocDay2" runat="server" Text='<%# Eval("AllocDay2") %>'></asp:Label>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Validator Equipment Status" UniqueName="ValStat" >
                      <ItemTemplate>
                          <asp:Label ID="lblValStat" runat="server" Text='<%# Eval("ValStat") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadComboBox ID="ValStat" runat="server"
                                AppendDataBoundItems="False"
                                SelectedValue='<%# Bind("ValStat") %>'
                                DataTextField="ValStat" 
                                DataValueField="ValStat"
                                Width="160pt">                                
                                <Items>
                                <telerik:RadComboBoxItem Text="Green" Value="Green" />
                                <telerik:RadComboBoxItem Text="Orange" Value="Orange" />
                                <telerik:RadComboBoxItem Text="Red" Value="Red" />
                                <telerik:RadComboBoxItem Text="Black" Value="Black" />
                                </Items>
                          </telerik:RadComboBox>
                      </EditItemTemplate>
                      </telerik:GridTemplateColumn>
  
                      <telerik:GridTemplateColumn AllowFiltering="False" HeaderText="Service Request Number" UniqueName="ServiceNumber" >
                      <ItemTemplate>
                          <asp:Label ID="lblServiceNumber" runat="server" Text='<%# Eval("ServiceNumber") %>'></asp:Label>
                      </ItemTemplate>
                      <EditItemTemplate>
                          <telerik:RadTextBox ID="ServiceNumber" Text='<%# Eval("ServiceNumber") %>' Runat="server" MaxLength="10"  >
                          </telerik:RadTextBox>   
                              <asp:RequiredFieldValidator ID="SerNumValidator" runat="server"
                              ErrorMessage="*" ControlToValidate="ValOp"></asp:RequiredFieldValidator>
                          <asp:RegularExpressionValidator ID="exValidator" runat="server" ErrorMessage="* Service Number Is Not Complete"
                           ControlToValidate="ServiceNumber" ValidationExpression=".{10}.*"></asp:RegularExpressionValidator
                            
                          </EditItemTemplate>
                            
                      </telerik:GridTemplateColumn>
              </Columns>
          </MasterTableView>
      </telerik:RadGrid>

Below is the NeedDatasource and OnSelectedChange events
protected void rgBusValidators_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            rgBusValidators.DataSource = BusList;
        }
  
protected void ValOp_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                GridEditableItem gRow = ((sender as RadComboBox).NamingContainer as GridEditableItem);
                RequiredFieldValidator snreq = ((RequiredFieldValidator)gRow["ServiceNumber"].FindControl("SerNumValidator"));
                if (e.Text == "Faulty")
                {
                    RadTextBox sntxt = ((RadTextBox)gRow["ServiceNumber"].FindControl("ServiceNumber"));
                    snreq.ControlToValidate = sntxt.ID;
                    snreq.IsValid = false;
                }
                else
                {
                    RadComboBox item = (RadComboBox)(sender);
                    snreq.ControlToValidate = item.ID;
                    snreq.IsValid = true;
                }
                  
            }
            catch (Exception ex)
            {
                lblError.Text = string.Format("Error: {0}", ex.Message);
                Log.Write(string.Format("Error Loading Data : {0}", ex.ToString()), Log.Category.IncidentManagementWeb, System.Diagnostics.TraceEventType.Error);
            }
        }

Please I need this urgantly

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 13 Aug 2012, 08:05 AM
Hello,

 I think the problem might be in the code behind logic for the SelectedIndexChanged event where you dynamically change the state and the control that is validated after postback. This probably interferes with the internal validation of the ASP.NET validator and it always turns invalid after postback.
It might be more appropriate to use custom validators in this case and manually determine when exactly the validated control is valid and when not.

Kind regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Shaun
Top achievements
Rank 1
answered on 13 Aug 2012, 08:52 AM
I understand that it could be a problem and will change the validator but I would like to know from the 125 records that are created why only the 2nd one is affected in this wat. does not matter if you edit it first or 20th only the second record is like that.
0
Marin
Telerik team
answered on 14 Aug 2012, 08:47 AM
Hello,

 I do not see any reason why this problem should be experienced only for a certain record unless there is something specific in the data that is validated for this record which causes the validator to become invalid.

Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Shaun
Top achievements
Rank 1
Answers by
Marin
Telerik team
Shaun
Top achievements
Rank 1
Share this question
or