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

[Solved] How to show update/insert/delete confirmation in rad window

3 Answers 493 Views
Grid
This is a migrated thread and some comments may be shown as answers.
eraashishgupta
Top achievements
Rank 1
eraashishgupta asked on 08 Jul 2010, 08:47 PM
Hi all ,
I am using Telerik grid to insert, update and delete records but my problem is i want to show the rad window alert message on successfull update,insert , or delete but i am unable to figure out how to trigger this.

Below is my rad grid code
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" PageSize="10"
        CssClass="RadGrid" AllowSorting="True" AutoGenerateColumns="False" ShowStatusBar="true"
        AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" AllowAutomaticInserts="true"
        OnNeedDataSource="RadGrid1_NeedDataSource" OnUpdateCommand="RadGrid1_UpdateCommand"
        OnInsertCommand="RadGrid1_InsertCommand" OnDeleteCommand="RadGrid1_DeleteCommand"
        OnItemDeleted="RadGrid1_ItemDeleted" OnItemUpdated="RadGrid1_ItemUpdated">
        <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="UserId">
            <Columns>
                <telerik:GridBoundColumn Visible="false" UniqueName="UserId" DataField="UserId" HeaderText="User Id" />
                <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" Visible="true"
                    UniqueName="FirstName" />
                <telerik:GridBoundColumn DataField="MiddleName" HeaderText="Middle Name" />
                <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" />
                <%-- <telerik:GridCalculatedColumn DataFields="FirstName, MiddleName, LastName" Expression="{0} +{1}  +{2}"
                        HeaderText="Name" />--%>
                <telerik:GridBoundColumn DataField="UserType.UserTypeName" HeaderText="Role" />
                <telerik:GridBoundColumn DataField="State.Name" HeaderText="State" />
                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Edit" ButtonType="ImageButton">
                </telerik:GridEditCommandColumn>
                <%-- <telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
                </telerik:GridEditCommandColumn>--%>
                <telerik:GridButtonColumn UniqueName="DeleteColumn" CommandName="Delete" HeaderText="Delete"
                    ButtonType="ImageButton" ConfirmDialogType="RadWindow" ConfirmText="Are you sure, you want to delete?"
                    ConfirmDialogHeight="100px" ConfirmTitle="Delete TIMS User">
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings UserControlName="~/UserControls/ManageUserControls/ManageUsers.ascx"
                EditFormType="WebUserControl">
                <EditColumn UniqueName="EditCommandColumn1">
                </EditColumn>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings EnableAlternatingItems="true" EnableRowHoverStyle="true" Selecting-AllowRowSelect="true">
            <ClientEvents OnRowDblClick="RowDblClick" />
        </ClientSettings>
    </telerik:RadGrid>
This is my insert command code
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
       {
           var editedItem = e.Item as GridEditableItem;
           var userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
           var user = new User();
           //const string radalertscript = "<script language='javascript'>function f(){radalert('Welcome to RadWindow <b>Prometheus</b>!', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
           //Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
           user.UserName = ((RadTextBox)userControl.FindControl("tbUserName")).Text;
           user.Password = Utility.EncryptTDC(((RadTextBox)userControl.FindControl("tbPassword")).Text);
           user.FirstName = ((RadTextBox)userControl.FindControl("tbFirstName")).Text;
           user.MiddleName = ((RadTextBox)userControl.FindControl("tbMiddleName")).Text;
           user.LastName = ((RadTextBox)userControl.FindControl("tbLastName")).Text;
           user.ContactPhoneMobile = ((RadTextBox)userControl.FindControl("tbHomePhone")).Text;
           user.ContactPhoneOffice = ((RadTextBox)userControl.FindControl("tbOfficePhone")).Text;
           if (((RadComboBox)userControl.FindControl("ddlState")).SelectedValue != "-1")
               user.StateId = Convert.ToInt32(((RadComboBox)userControl.FindControl("ddlState")).SelectedValue);
           if (((RadComboBox)userControl.FindControl("ddlInstitute")).SelectedValue != "-1")
               user.InstituteId = Convert.ToInt32(((RadComboBox)userControl.FindControl("ddlInstitute")).SelectedValue);
           if (((RadComboBox)userControl.FindControl("ddlTrainer")).SelectedValue != "-1")
               user.TrainerId = Convert.ToInt32(((RadComboBox)userControl.FindControl("ddlTrainer")).SelectedValue);
 
           user.UserTypeId = Convert.ToInt32(((RadComboBox)userControl.FindControl("ddlUserType")).SelectedValue);
           user.DateCreated = DateTime.Now;
 
           //string radalertscript =
           //    "<script language='javascript'>function f(){radalert('main text to display', 340, 110, 'new title');}</script>";
 
           ClientScript.RegisterStartupScript(this.GetType(), "radalert", "callAlert();", true);
 
           var userServiceContext = new TimsService<User>();
           var result = userServiceContext.Create(user);
 
           if (result)
           {
               ((RadTextBox)userControl.FindControl("tbUserName")).Text = "";
               ((RadTextBox)userControl.FindControl("tbPassword")).Text = "";
               ((RadTextBox)userControl.FindControl("tbReEnterPassword")).Text = "";
               ((RadTextBox)userControl.FindControl("tbFirstName")).Text = "";
               ((RadTextBox)userControl.FindControl("tbMiddleName")).Text = "";
               ((RadTextBox)userControl.FindControl("tbLastName")).Text = "";
               ((RadTextBox)userControl.FindControl("tbHomePhone")).Text = "";
               ((RadTextBox)userControl.FindControl("tbOfficePhone")).Text = "";
               ((RadComboBox)userControl.FindControl("ddlState")).SelectedValue = "-1";
               ((RadComboBox)userControl.FindControl("ddlInstitute")).SelectedValue = "-1";
               ((RadComboBox)userControl.FindControl("ddlTrainer")).SelectedValue = "-1";
               ((RadComboBox)userControl.FindControl("ddlUserType")).SelectedValue = "-1";
 
 
               const string radalertscript = "<script language='javascript'>function f(){radalert('Welcome to RadWindow <b>Prometheus</b>!', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
               Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript, true);
               //RadGrid1.ItemInserted += RadGrid1_ItemInserted;
                
           }
       }

The rad windows inside this is also not called
Below is the code written on item inserted
protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
       {
           const string radalertscript = "<script language='javascript'>function f(){radalert('Welcome to RadWindow <b>Prometheus</b>!', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
           Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript, true);
       }
Neither this is called and works though there is successfull insert in the database.

Help is highly  appreciated.
Thanks,

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 13 Jul 2010, 12:13 PM
Hi eraashishgupta,

RadGrid's ItemInserted / ItemUpdated / ItemDeleted events fire only after automatic data source operations with data source controls. You cannot use any of these in this case. On a side note, you need to also remove AllowAutomaticUpdates / Deletes / Inserts from the RadGrid markup, because these work with declarative data source controls only.

You are left with InsertCommand / UpdateCommand and I can see you are using Page.ClientScript.RegisterStartupScript. Now, in regular scenarios without AJAX postbacks, this would work perfectly. However, if RadGrid is AJAX-ified and your updates / inserts occur through asynchronous posrbacks, methods in Page.ClientScript will not work. They are not supported by the AJAX framework. You need to use ScriptManager.RegiserStartupScript instead.

Other than that, the script you include seems fine. I can note you correctly observe the rules for invoking methods of client-side AJAX component from the server. For the rest of our readers - here is a detailed explanation on how to execute javscript methods from the server-side.

Best,
Veli
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
Sonny
Top achievements
Rank 1
answered on 25 Jun 2014, 03:53 PM
0
Marin Bratanov
Telerik team
answered on 26 Jun 2014, 06:58 AM

Hi Sonny,

Here is the correct link: http://blogs.telerik.com/aspnet-ajax/posts/09-05-05/executing-javascript-function-from-server-side-code.aspx. I have also fixed the on in my colleague's post.


Regards,

Marin Bratanov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
eraashishgupta
Top achievements
Rank 1
Answers by
Veli
Telerik team
Sonny
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or