I have a radGrid that has inline Edit enabled. When the user clicks the inline Update link the RadGrid_UpdateCommand is triggered. Within that command I make a call to a PageValidate method. If this fails I'm trying to display a message to the screen via a ASP:Label. However the Label is not getting properly refreshed. I have created a button on the page and used the RadAjaxmanager to link the button to the label to test that the label does indeed get the proper value. However I need to ensure that when I click update and the validation fails that the error message is properly displayed (label is refreshed).
ASPX Code:
C# Code:
Any help is greatly appreciated.
ASPX Code:
| <rad:RadAjaxPanel ID="errorMessageAjaxPanel" EnableAJAX="true" runat="server"> |
| <asp:Label ID="errorMessageLabel" runat="server" Font-Bold="true" ForeColor="Red"></asp:Label> |
| </rad:RadAjaxPanel> |
| <asp:Button ID="button" runat="server" /> |
| <table width="80%" style="margin-left: auto; margin-right: auto;" border="0"> |
| <tr> |
| <td> |
| <div style="float: left; margin: 5px 5px 10px 5px;"> |
| Select Holiday Year: |
| <asp:DropDownList ID="holidayYear" AutoPostBack="true" runat="server" OnSelectedIndexChanged="holidayYear_SelectedIndexChanged"> |
| </asp:DropDownList> |
|   |
| </div> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <rad:RadGrid ID="holidayRadGrid" AllowPaging="True" AllowSorting="True" GridLines="Horizontal" |
| HorizontalAlign="Center" ShowFooter="true" ShowStatusBar="true" EnableAJAX="true" |
| EnableAJAXLoadingTemplate="True" LoadingTemplateTransparency="25" AutoGenerateColumns="False" |
| Skin="Grid" SkinsPath="~/App_Themes/VertexDefault" OnNeedDataSource="holidayRadGrid_NeedDataSource" |
| OnUpdateCommand="holidayRadGrid_UpdateCommand" |
| PageSize="18" runat="server"> |
| <MasterTableView DataKeyNames="HolidayID,HolidayYear,HolidayDate,HolidayName" EditMode="InPlace" |
| TableLayout="Auto" AllowNaturalSort="false" BorderColor="Black"> |
| <Columns> |
| <rad:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderStyle-Width="10px" /> |
| <rad:GridBoundColumn HeaderStyle-Width="60px" DataField="HolidayName" HeaderText="Holiday" |
| SortExpression="HolidayName" UniqueName="HolidayName" ReadOnly="true" /> |
| <rad:GridTemplateColumn HeaderStyle-Width="100px" DataField="HolidayDate" SortExpression="HolidayDate" |
| UniqueName="HolidayDate"> |
| <ItemTemplate> |
| <asp:Label ID="holidayDateLabel" Text='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? String.Empty : String.Format("{0:MM/dd/yyyy}", Eval("HolidayDate")) %>' |
| runat="server" /> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:Calendar ID="holidayDateCalendar" SelectedDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>' |
| VisibleDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>' |
| runat="server" /> |
| <%--<rad:RadCalendar ID="holidayDateCalendar" AutoPostBack="false" EnableMultiSelect="false" SelectedDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>' VisibleDate='<%# (DateTime) Eval("HolidayDate") == DateTime.MinValue ? ValidDate : Eval("HolidayDate") %>' runat="server" />--%> |
| </EditItemTemplate> |
| </rad:GridTemplateColumn> |
| <rad:GridBoundColumn DataField="HolidayID" UniqueName="HolidayID" ReadOnly="true" |
| Display="false" /> |
| <rad:GridBoundColumn DataField="HolidayYear" UniqueName="HolidayYear" ReadOnly="true" |
| Display="false" /> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings EnablePostBackOnRowClick="true"> |
| <ClientEvents OnGridCreated="holidayRadGridCreated" OnRowContextMenu="holidayRadGridRowContextMenu" /> |
| </ClientSettings> |
| </rad:RadGrid> |
| <br /> |
| <div> |
| <vtx:ImageHoverButton ID="cancelButton" PostBackUrl="~/Home.aspx" ImageUrl="~/App_Themes/VertexDefault/Images/CancelNormal.png" |
| CssClass="ImageHover" AlternateText="Search" runat="server" /> |
| </div> |
| </td> |
| </tr> |
| </table> |
| <asp:Panel ID="actionPanel" runat="server" Style="display: none" CssClass="modalPopup"> |
| <asp:Panel ID="titlePanel" CssClass="modalTitle" BackImageUrl="~/App_Themes/VertexDefault/Images/ModalTitleGradient.jpg" |
| runat="server"> |
| <div> |
| <table width="100%"> |
| <tr> |
| <td style="width: 99%"> |
| <asp:Label ID="titleLabel" Text="Change status" runat="server" /> |
| </td> |
| <td align="right"> |
| <asp:ImageButton ID="closeButton" AlternateText="Close" ImageUrl="~/App_Themes/VertexDefault/Images/Close.png" |
| runat="server" /> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </asp:Panel> |
| <div style="margin-top: 10px"> |
| Confirm delete of Holiday Date<br /> |
| <b> |
| <asp:Label ID="lblHolidayDate" runat="Server" /></b> for Holiday: <b> |
| <asp:Label ID="lblHolidayName" runat="server" /></b> |
| <input type="hidden" id="holidayIDHidden" runat="server" /> |
| <input type="hidden" id="holidayNameHidden" runat="server" /> |
| <input type="hidden" id="holidayYearHidden" runat="server" /> |
| <input type="hidden" id="holidayDateHidden" runat="server" /> |
| <input type="hidden" id="errorMessageHidden" runat="server" /> |
| </div> |
| <br /> |
| <asp:Button ID="applyButton" Text="Apply" OnClick="applyButton_Click" runat="server" /><br /> |
| |
| </asp:Panel> |
| <asp:Button ID="hiddenButton" Style="display: none" runat="server" /> |
| <atk:ModalPopupExtender ID="actionPanelModalPopupExtender" BehaviorID="actionModalBehavior" |
| PopupControlID="actionPanel" TargetControlID="hiddenButton" CancelControlID="closeButton" |
| PopupDragHandleControlID="titlePanel" DropShadow="true" runat="server" /> |
| <rad:RadAjaxManager ID="ajaxManager" ClientEvents-OnResponseReceived="hideModalPopup()" |
| runat="server"> |
| <AjaxSettings> |
| <rad:AjaxSetting AjaxControlID="applyButton"> |
| <UpdatedControls> |
| <rad:AjaxUpdatedControl ControlID="applyButton" /> |
| <rad:AjaxUpdatedControl ControlID="errorMessageLabel" /> |
| <rad:AjaxUpdatedControl ControlID="holidayRadGrid" LoadingPanelID="holidayRadGridLoadingPanel" /> |
| </UpdatedControls> |
| </rad:AjaxSetting> |
| <rad:AjaxSetting AjaxControlID="button"> |
| <UpdatedControls> |
| <rad:AjaxUpdatedControl ControlID="errorMessageLabel" /> |
| </UpdatedControls> |
| </rad:AjaxSetting> |
| </AjaxSettings> |
| </rad:RadAjaxManager> |
| <rad:AjaxLoadingPanel ID="holidayRadGridLoadingPanel" runat="Server"> |
| <asp:Image ID="loadingImage" ImageUrl="~/App_Themes/VertexDefault/Grid/Loading.gif" |
| AlternateText="Loading" BorderWidth="0px" runat="server" /> |
| </rad:AjaxLoadingPanel> |
| <rad:RadMenu ID="gridContextRadMenu" IsContext="True" OnClientItemClicked="OnClientItemClickedHandler" |
| ContextMenuElementID="none" Skin="Menu" SkinsPath="~/App_Themes/VertexDefault" |
| runat="server"> |
| <Items> |
| <rad:RadMenuItem Text="Delete the date for this Holiday?" Value="CS" /> |
| </Items> |
| </rad:RadMenu> |
C# Code:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| log.Debug("Page_Load"); |
| // Get current user and customer |
| User user = Master.CurrentUser; |
| Customer customer = GetCustomer(user); |
| // Set year for page heading |
| int holidayYearPlusOne = System.DateTime.Now.Year + 1; |
| int holidayYearPlusTwo = System.DateTime.Now.Year + 2; |
| lblHolidayYear.Text = System.DateTime.Now.Year.ToString(); |
| if (!IsPostBack) |
| { |
| int currentHolidayYear = Convert.ToInt32(DateTime.Now.ToString("yyyy")); |
| // Populate filing year dropdown |
| holidayYear.Items.Add(new ListItem(System.DateTime.Now.Year.ToString(), System.DateTime.Now.Year.ToString())); |
| holidayYear.Items.Add(new ListItem(holidayYearPlusOne.ToString(), holidayYearPlusOne.ToString())); |
| holidayYear.Items.Add(new ListItem(holidayYearPlusTwo.ToString(), holidayYearPlusTwo.ToString())); |
| // Clear old data |
| Session.Remove(Constants.Session.PageData); |
| // Build data |
| BuildTable(currentHolidayYear); |
| } |
| else |
| { |
| // Set year for page heading |
| lblHolidayYear.Text = holidayYear.SelectedValue; |
| } |
| // Checks page security |
| CheckPageSecurity(customer, user); |
| } |
| /// <summary> |
| /// Handles the SelectedIndexChanged event of the holidayYear control. |
| /// </summary> |
| /// <param name="sender">The source of the event.</param> |
| /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> |
| protected void holidayYear_SelectedIndexChanged(object sender, EventArgs e) |
| { |
| log.Debug("holidayYear_SelectedIndexChanged"); |
| if (returns == null) |
| { |
| // Create returns manager |
| returns = ReturnsFactory.CreateReturns(); |
| } |
| // Clear old data |
| Session.Remove(Constants.Session.PageData); |
| // Build data |
| BuildTable(Convert.ToInt32(holidayYear.SelectedValue.ToString())); |
| // Set year for page heading |
| lblHolidayYear.Text = holidayYear.SelectedValue; |
| // Clear out edit mode for items in grid |
| holidayRadGrid.MasterTableView.ClearEditItems(); |
| holidayRadGrid.Rebind(); |
| } |
| #endregion |
| #region Private Methods |
| /// <summary> |
| /// Builds the table. |
| /// </summary> |
| private void BuildTable(int currentHolidayYear) |
| { |
| log.Debug("BuildTable"); |
| try |
| { |
| if (returns == null) |
| { |
| // Create returns manager |
| returns = ReturnsFactory.CreateReturns(); |
| } |
| // Clear out any errors that may have been displayed to the screen |
| errorMessageLabel.Text = ""; |
| // Set 'Year' |
| validDate = new DateTime(Convert.ToInt32(holidayYear.SelectedValue), DateTime.Now.Month, DateTime.Now.Day); |
| // Fetch Holidays |
| Holidays holidays = (Holidays)Session[Constants.Session.PageData]; |
| // Get Holidays if they are not already in the session |
| if (holidays == null) |
| { |
| holidays = returns.GetHolidays(currentHolidayYear); |
| Session[Constants.Session.PageData] = holidays; |
| } |
| holidayRadGrid.DataSource = holidays.Values; |
| //holidayRadGrid.DataBind(); |
| if (errorMessageHidden.Value.Length > 0) |
| { |
| errorMessageLabel.Text = errorMessageHidden.Value; |
| } |
| // Set correct year to be used for the column HolidayDate's Header Text |
| holidayRadGrid.MasterTableView.GetColumn("HolidayDate").HeaderText = holidayYear.SelectedValue; |
| //holidayRadGrid.Rebind(); |
| } |
| catch (Exception ex) |
| { |
| log.Error("Error occurred in page '{0}'. Message: '{1}'", Request.Url.Segments[Request.Url.Segments.Length - 1], ex.Message); |
| Response.Redirect(Constants.Pages.ErrorPage); |
| } |
| } |
| /// <summary> |
| /// Checks the page security. |
| /// </summary> |
| /// <param name="customer">The customer.</param> |
| /// <param name="user">The user.</param> |
| private void CheckPageSecurity(Customer customer, User user) |
| { |
| log.Debug("CheckPageSecurity"); |
| // Allow delete/delete? |
| allowDelete = Master.CheckPageSecurity(customer, user, string.Format(@"{0}/Delete", AppRelativeVirtualPath)) == Permission.EditExecute; |
| } |
| /// <summary> |
| /// Gets the customer. |
| /// </summary> |
| /// <param name="user">The user.</param> |
| /// <returns></returns> |
| private Customer GetCustomer(User user) |
| { |
| // Get current customer |
| Customer customer = Master.CurrentCustomer; |
| // Customer specified on the querystring? |
| if (Request[Constants.QueryString.Customer] != null) |
| { |
| if (!Request[Constants.QueryString.Customer].Equals(customer.CustomerNumber, StringComparison.OrdinalIgnoreCase)) |
| { |
| if (returns == null) |
| { |
| // Create returns manager |
| returns = ReturnsFactory.CreateReturns(); |
| } |
| // Only allowed to specify a different customer if we are a Vertex user |
| if (!returns.IsVertexUser(user)) |
| { |
| // Log security violation |
| returns.LogSecurityViolation(user, string.Format("Attempt to access UserList.aspx with querystring '{0}'.", Request.QueryString)); |
| Response.Redirect(Constants.Pages.HomePage); |
| } |
| // Get customer |
| customer = returns.GetCustomer(Request[Constants.QueryString.Customer]); |
| } |
| } |
| return customer; |
| } |
| /// <summary> |
| /// Handles the UpdateCommand event of the holidayRadGrid control. |
| /// </summary> |
| /// <param name="source">The source of the event.</param> |
| /// <param name="e">The <see cref="Telerik.WebControls.GridCommandEventArgs"/> instance containing the event data.</param> |
| protected void holidayRadGrid_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditableItem eeditedItem = e.Item as GridEditableItem; |
| // Get current user and customer |
| User user = Master.CurrentUser; |
| try |
| { |
| if (returns == null) |
| { |
| // Create returns manager |
| returns = ReturnsFactory.CreateReturns(); |
| } |
| // Find controls in the edit item template |
| GridEditableItem item = (GridEditableItem)e.Item; |
| Calendar holidayDateCalendar = (Calendar) item.FindControl("holidayDateCalendar"); |
| // Validate input fields |
| if (!ValidateInput(holidayDateCalendar.SelectedDate)) |
| { |
| holidayRadGrid.Rebind(); |
| return; |
| } |
| // If the old value is equal to "1/1/0001 12:00:00 AM" then the a date for this holiday |
| // has never been set. |
| if ((DateTime)editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["HolidayDate"] == DateTime.MinValue) |
| { |
| // INSERT |
| Holiday holiday = new Holiday(); |
| holiday.HolidayDate = Convert.ToDateTime(holidayDateCalendar.SelectedDate); |
| holiday.HolidayYear = Convert.ToInt32(holidayYear.SelectedValue.ToString()); |
| holiday.HolidayID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["HolidayID"].ToString()); |
| returns.CreateHolidayDate(holiday, user.UserID); |
| } |
| else |
| { |
| // UPDATE |
| Holiday holiday = new Holiday(); |
| holiday.HolidayDate = Convert.ToDateTime(holidayDateCalendar.SelectedDate); |
| holiday.HolidayYear = Convert.ToInt32(holidayYear.SelectedValue.ToString()); |
| holiday.HolidayID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["HolidayID"].ToString()); |
| returns.UpdateHolidayDate(holiday, user.UserID); |
| } |
| // Refresh grid |
| holidayRadGrid.DataSource = returns.GetHolidays(Convert.ToInt32(holidayYear.SelectedValue.ToString())).Values; |
| holidayRadGrid.Rebind(); |
| Response.Redirect(ReturnsConstants.Pages.HolidayListEdit); |
| } |
| catch (Exception ex) |
| { |
| // Log error |
| log.Error("Error occurred in page '{0}'. Message: '{1}'", Request.Url.Segments[Request.Url.Segments.Length - 1], ex.Message); |
| e.Canceled = true; |
| } |
| } |
| //protected void holidayRadGrid_ItemDataBound(object sender, GridItemEventArgs e) |
| //{ |
| // log.Debug("holidayRadGrid_ItemCreated"); |
| // if ((e.Item.ItemType == GridItemType.Item) || (e.Item.ItemType == GridItemType.AlternatingItem)) |
| // { |
| // if (e.Item is GridEditableItem) |
| // { |
| // GridEditableItem item = (GridEditableItem) e.Item; |
| // Calendar holidayDateCalendar = (Calendar) item.FindControl("holidayDateCalendar"); |
| // if (holidayDateCalendar != null) |
| // { |
| // holidayDateCalendar.SelectedDate = ValidDate; |
| // holidayDateCalendar.VisibleDate = ValidDate; |
| // } |
| // } |
| // } |
| //} |
| /// <summary> |
| /// Handles the NeedDataSource event of the holidayRadGrid control. |
| /// </summary> |
| /// <param name="source">The source of the event.</param> |
| /// <param name="e">The <see cref="Telerik.WebControls.GridNeedDataSourceEventArgs"/> instance containing the event data.</param> |
| protected void holidayRadGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| log.Debug("holidayRadGrid"); |
| // Fetch holiday Dates |
| //Holidays holidays = (Holidays)Session[Constants.Session.PageData]; |
| //holidayRadGrid.DataSource = holidays.Values; |
| BuildTable(Convert.ToInt32(DateTime.Now.ToString("yyyy"))); |
| if (errorMessageHidden.Value.Length != 0) |
| { |
| errorMessageLabel.Text = errorMessageHidden.Value; |
| } |
| } |
| /// <summary> |
| /// Handles the Click event of the applyButton control. |
| /// </summary> |
| /// <param name="sender">The source of the event.</param> |
| /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> |
| protected void applyButton_Click(object sender, EventArgs e) |
| { |
| log.Debug("applyButton_Click"); |
| try |
| { |
| if (returns == null) |
| { |
| // Create returns factory |
| returns = ReturnsFactory.CreateReturns(); |
| } |
| // Get update user details |
| User user = Master.CurrentUser; |
| // Delete holiday date for a specific holiday |
| if (holidayDateHidden.Value.Length > 0) |
| { |
| Holiday holiday = returns.GetHolidayDate(Convert.ToInt32(holidayIDHidden.Value.ToString()), Convert.ToInt32(holidayYearHidden.Value.ToString()), Convert.ToDateTime(holidayDateHidden.Value)); |
| returns.DeleteHolidayDate(holiday, user.UserID); |
| } |
| else |
| { |
| errorMessageLabel.Text = "You cannot delete an entry that has no date associated to it."; |
| //errorMessagePanel.Visible = true; |
| } |
| Holidays holidays = new Holidays(); |
| holidays = returns.GetHolidays(Convert.ToInt32(holidayYear.SelectedValue.ToString())); |
| holidayRadGrid.DataSource = holidays.Values; |
| holidayRadGrid.Rebind(); |
| // Store data |
| Session[Constants.Session.PageData] = holidays; |
| } |
| catch (Exception ex) |
| { |
| log.Error("Error occurred in page '{0}'. Message: '{1}'", Request.Url.Segments[Request.Url.Segments.Length - 1], ex.Message); |
| Response.Redirect(Constants.Pages.ErrorPage); |
| } |
| } |
| private bool ValidateInput(DateTime holidayDate) |
| { |
| log.Debug("ValidateInput"); |
| // If page is not valid then let the client side show it's errors |
| if (Page.IsValid) |
| { |
| // Re-validate page (in case client side validation did not work) |
| Page.Validate(); |
| } |
| // If page is not valid then let the client side show it's errors |
| if (!Page.IsValid) |
| { |
| return false; |
| } |
| try |
| { |
| if (holidayDate.Year.ToString() != holidayYear.SelectedValue) |
| { |
| errorMessageHidden.Value = string.Format("You must select a date that occurs within the currently selected year '{0}'.", holidayYear.SelectedValue); |
| Master.MessageBox.Show(string.Format("You must select a date that occurs within the currently selected year '{0}'.", holidayYear.SelectedValue), MessageBoxIcon.Error); |
| return false; |
| } |
| } |
| catch (Exception ex) |
| { |
| log.Error("Error occurred in page '{0}'. Message: '{1}'", Request.Url.Segments[Request.Url.Segments.Length - 1], ex.Message); |
| return false; |
| } |
| return true; |
| } |
| #endregion |
| #region Properties |
| /// <summary> |
| /// Gets a value indicating whether [allow delete]. |
| /// </summary> |
| /// <value><c>true</c> if [allow delete]; otherwise, <c>false</c>.</value> |
| protected string AllowDelete |
| { |
| get { return allowDelete.ToString().ToLower(); } |
| } |
| /// <summary> |
| /// Gets a value indicating whether [allow disable]. |
| /// </summary> |
| /// <value><c>true</c> if [allow disable]; otherwise, <c>false</c>.</value> |
| protected string AllowDisable |
| { |
| get { return allowDisable.ToString().ToLower(); } |
| } |
| /// <summary> |
| /// Gets the valid date. |
| /// </summary> |
| /// <value>The valid date.</value> |
| protected DateTime ValidDate |
| { |
| get { return validDate; } |
| } |
| #endregion |
| #region Fields |
| private bool allowDelete = true; |
| private bool allowDisable = true; |
| private IReturnsManager returns = null; |
| private DateTime validDate; |
| #endregion |
Any help is greatly appreciated.