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

unable to registerStartupScript during RadGrid UpdateCommand

2 Answers 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom M
Top achievements
Rank 1
Tom M asked on 08 Oct 2010, 02:40 PM
Greetings All,

I am trying to register some startup script during the update command of a radGrid that I have. Not sure why, but this isn't working for me.

Here is the radWindowManager markup...
<telerik:RadWindowManager ID="RadWindowManager1" runat="server" IconUrl="../CSS/titlegraphic.gif">
</telerik:RadWindowManager>

Here is the scriptManager on the MasterPage..
<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
       <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
       <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    </Scripts>
</asp:ScriptManager>

Here is the radGrid markup (contained in a radAjaxPanel)..
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
            <telerik:RadGrid runat="server" ID="ReportGrid" Width="936px" GridLines="Horizontal"
                                AllowPaging="True" AllowSorting="True" AllowFilteringByColumn="True" PageSize="10"
                                OnNeedDataSource="ReportGrid_NeedDataSource"
                                OnUpdateCommand="ReportGrid_UpdateCommand"
                                >
                <MasterTableView DataKeyNames="pa,report_close_id" AutoGenerateColumns="false" EditMode="InPlace" CommandItemDisplay="None">
                    <FilterItemStyle HorizontalAlign="Center" />
                    <Columns>
                        <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit" HeaderStyle-Width="66px" HeaderStyle-HorizontalAlign="Center" >                 
                            <ItemStyle Width="66px" HorizontalAlign="Center" />
                        </telerik:GridEditCommandColumn>
                        <telerik:GridBoundColumn DataField="report_close_id" HeaderText="Report Close ID" UniqueName="report_close_id" Visible="false" >
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="client_id" HeaderText="Client ID" UniqueName="client_id" Visible="false" >
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="client_name" HeaderText="Client Name" ReadOnly="true" UniqueName="client_name" Visible="true" HeaderStyle-Width="215px" >
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="pa" HeaderText="Performance Analyst" ReadOnly="true" UniqueName="pa" Visible="true" HeaderStyle-Width="165px" >
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn DataField="requested_date" HeaderText="Requested Completion By" UniqueName="requested_date"
                                                  HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="120px" >
                            <ItemStyle HorizontalAlign="Center" Width="120px" />
                            <ItemTemplate>
                                <asp:Label ID="lblRequestedDate" runat="server" Text='<%# Bind("requested_date", "{0:MM/dd/yyyy}") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDatePicker ID="RequestedDatePicker" runat="server" Width="90px" DbSelectedDate='<%# Bind("requested_date", "{0:MM/dd/yyyy}") %>'>
                                </telerik:RadDatePicker>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="actual_date" HeaderText="Date Completed" UniqueName="actual_date"
                                                  HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="120px" >
                            <ItemStyle HorizontalAlign="Center" Width="120px" />
                            <ItemTemplate>
                                <asp:Label ID="lblCompletedDate" runat="server" Text='<%# Bind("actual_date", "{0:MM/dd/yyyy}") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDatePicker ID="CompletedDatePicker" runat="server" Width="90px" DbSelectedDate='<%# Bind("actual_date", "{0:MM/dd/yyyy}") %>'>
                                </telerik:RadDatePicker>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn
                        <telerik:GridTemplateColumn DataField="comments" HeaderText="Comments" UniqueName="comments" 
                                                  HeaderStyle-HorizontalAlign="Center" HeaderStyle-Width="210px" ItemStyle-Width="210px" ItemStyle-HorizontalAlign="Center">
                            <ItemTemplate>
                                <asp:Label ID="lblComments" runat="server" Text='<%# Eval("comments") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadTextBox ID="txtComments" runat="server" MaxLength="500" Width="175px" Rows="3" Text='<%# Eval("comments") %>' TextMode="MultiLine">
                                </telerik:RadTextBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
            </telerik:RadGrid>
            <br />
            <asp:Button ID="btnSave" runat="server" Text="Save" visible="false"/>
            <asp:Button ID="btnCancel" runat="server" Text="Cancel/Exit" OnClientClick="Close()" />
        </telerik:RadAjaxPanel>

Here is the updateCommand code.. The ScriptManager.RegisterStartupScript() call is near the end of the function.
protected void ReportGrid_UpdateCommand(object source, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.UpdateCommandName)
    {
        try
        {
        //Get the GridEditableItem of the RadGrid
        GridEditableItem editedItem = e.Item as GridEditableItem;
        int report_close_id = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["report_close_id"].ToString());
        ReportCloseDateBO updated_close = new ReportCloseDateBO();
        updated_close.FillByCloseDateID(report_close_id);
        DateTime actual_date_cell = new DateTime();
        DateTime requested_date_cell = new DateTime();
        DateTime updated_requested_completion_date = new DateTime(1855, 1, 1);
        DateTime updated_actual_completion_date = new DateTime(1855, 1, 1);
        string comments = ((editedItem["comments"].Controls[1] as RadTextBox).Text);
        ClientBO client = new ClientBO();
        client.FillClientByID(updated_close.client_id);
        bool pa_assigned = true;
        string pa_email = "";
        bool actual_completion_changed = false;
        bool requested_completion_changed = false;
        bool error_ind = false;
        PERAPositionBO peraPosition = new PERAPositionBO();
        if (!(editedItem["actual_date"].Controls[1] as RadDatePicker).IsEmpty)
        {
            actual_date_cell = ((editedItem["actual_date"].Controls[1] as RadDatePicker).SelectedDate.Value);
        }
        else 
        {
            actual_date_cell = new DateTime(1855, 1, 1);
        }
        if (!(editedItem["requested_date"].Controls[1] as RadDatePicker).IsEmpty )
        {
            requested_date_cell = ((editedItem["requested_date"].Controls[1] as RadDatePicker).SelectedDate.Value);
        }
        else
        {
            requested_date_cell = new DateTime(1855, 1, 1);
        }
        if (client.pa_user_id != -1)
        {
            ApplicationUserBO pa_user = new ApplicationUserBO();
            pa_user.FillByUserID(client.pa_user_id);
            pa_email = pa_user.e_mail;
        }
        else
        {
            pa_assigned = false;
        }
        //First check to see if the requested completion date has changed
        if (requested_date_cell != null)
        {
            //Check to see if the value has already been entered into the database
            updated_requested_completion_date = requested_date_cell;
            if (updated_close.requested_completion != updated_requested_completion_date)
            {
                requested_completion_changed = true;
            }
            else
            {
                requested_completion_changed = false;
            }
        }
        else
        {
            requested_completion_changed = false;
        }
        //Now check to see if a value has been entered into the actual completion date cell
        if (actual_date_cell != null)
        {
            //Check to see if the value has already been entered into the database
            updated_actual_completion_date = actual_date_cell;
            if (updated_close.actual_completion != updated_actual_completion_date)
            {
                actual_completion_changed = true;
            }
            else
            {
                actual_completion_changed = false;
            }
        }
        else
        {
            actual_completion_changed = false;
        }
        //Update the request date
        if (requested_completion_changed)
        {
            try
            {
                updated_close.UpdateRequestedReportCloseDate(report_close_id, updated_requested_completion_date, comments);
            }
            catch (Exception exe)
            {
                error_ind = true;
                //MessageBox.Show(exe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //logger.RecordMessage(exe, Log.MessageType.Error, parent.UserID);
            }
        }
        //Update the actual completion date
        if (actual_completion_changed)
        {
            try
            {
                updated_close.UpdateActualReportCloseDate(report_close_id, updated_actual_completion_date, comments);
                updated_close = new ReportCloseDateBO();
                updated_close.FillByCloseDateID(report_close_id);
                //Now calculate the PERA position and put it in the pera position table.
                peraPosition = new PERAPositionBO();
                peraPosition.InsertPERAPosition(updated_close.client_id, updated_close.report_dated);
                //offer to notify the PA via email
                if (pa_assigned)
                {
                    int sendEmail = Convert.ToInt32(ConfigurationManager.AppSettings["SendEmail"]);
                    if (sendEmail == 1)
                    {
                        string userName = User.Identity.Name.ToString();
                        string[] tokens = userName.Split('\\');
                        ApplicationUserBO current_user = new ApplicationUserBO();
                        //current_user.FillByUserID(parent.UserID);
                        current_user.FillByUserID(7);
                        string body = tokens[1].ToString() + " has completed " + client.client_name + "'s PE report for " + updated_close.report_dated.ToShortDateString();
                        string subject = client.client_name + " PE Report Completed";
                        string to = current_user.e_mail.ToString();
                        string from = "PERA@haifc.com";
                        Session.Add("from", from);
                        Session.Add("to", to);
                        Session.Add("subject", subject);
                        Session.Add("body", body);
                        
                                 ScriptManager.RegisterStartupScript(this, this.GetType(), "mykey", "radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');", true);
                        //RadAjaxManager1.ResponseScripts.Add("radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');");
                          
                        //ClientScriptManager cs = Page.ClientScript;
                        //cs.RegisterClientScriptBlock(this.GetType(), "popupScript", RadWindowManager1.ClientID + ".radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');", true);
                        //ClientScript.RegisterStartupScript(Page.GetType(), "popupScript", "radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');", true);
                    }
                }
            }
            catch (Exception exe)
            {
                error_ind = true;
                //MessageBox.Show(exe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //logger.RecordMessage(exe, Log.MessageType.Error, parent.UserID);
            }
           }
                             
        }
        catch (Exception ex)
        {
            ReportGrid.Controls.Add(new LiteralControl("Unable to update. Reason: " + ex.Message));
            //logger.RecordMessage(exe, Log.MessageType.Error, parent.UserID);
            e.Canceled = true;
        }
    }
}


The updateCommand works as I would expect, however there is no radconfirm following the update. Any help or thoughts would be most appreciated.

Regards,
Tom

2 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 14 Oct 2010, 08:02 AM
Hello Tom,

Can you try modifying the code for registering the scripts as below and see if it makes any difference:

ScriptManager.RegisterStartupScript(Page, typeof(Page), "mykey"
    "radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');", true); 


Best wishes,
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
0
Tom M
Top achievements
Rank 1
answered on 14 Oct 2010, 05:00 PM
Hi Iana,

Thank you for your reply. I was able to figure out what was wrong...the single quote in the script string was causing the issue.

ScriptManager.RegisterStartupScript(this, this.GetType(), "mykey", "radconfirm('Would you like to notify " + client.client_name + "'s" + " PA?', confirmCallBackFn, 330, 100, null,'Send Message?');", true);

I replaced the " ' s " with " \\ ' s " and it now works as I would expect. Rookie mistake.

Kind Regards,
Tom
Tags
Grid
Asked by
Tom M
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Tom M
Top achievements
Rank 1
Share this question
or