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

EditForm not closing when command is passed

4 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jaymie
Top achievements
Rank 1
Jaymie asked on 19 Jan 2011, 02:39 PM
Hi,

I have seen others post this issue, but I believe mine is slightly different.
Take a look at the following code:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="btnSave">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="CreatePanel" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="rgCampaigns" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="EditFailureText" />
                <telerik:AjaxUpdatedControl ControlID="ValidationSummary1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="rgCampaigns">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rgCampaigns" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="EditFailureText" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Default" BackgroundPosition="Center" EnableSkinTransparency="true">
</telerik:RadAjaxLoadingPanel>
 
<h1>Campaigns</h1>
<p>Before you can create any content to share with your Partners, you must first create a campaign. This will allow your partners the ability to access any resources you share for the campaign.</p>
 
<asp:Panel runat="server" ID="CreatePanel">  
    <h2>Create your campaign(s)</h2>    
    <p>
        <asp:Label ID="CreateFailureText" runat="server" ForeColor="Red" />
    </p>
    <fieldset class="register">
        <legend>Create campaign</legend>
        <table>
            <tr>
                <td colspan="3"><asp:ValidationSummary ID="ValidationSummary1" ForeColor="Red" DisplayMode="SingleParagraph" HeaderText="You must complete the fields marked with a *" runat="server" /></td>                       
            </tr>
            <tr>
                <td>
                    Name:</td>
                <td>
                    <telerik:RadTextBox ID="txtName" runat="server"
                        EmptyMessage="Please type a name for the campaign" Width="230px">
                    </telerik:RadTextBox>
                </td>
                <td>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                        ControlToValidate="txtName" ErrorMessage=""></asp:RequiredFieldValidator>
                    <font color="red">*</font></td>
            </tr>
            <tr>
                <td>
                    Description</td>
                <td>
                    <telerik:RadTextBox ID="txtDescription" runat="server"
                        EmptyMessage="Please type a description for your campaign" Rows="5"
                        style="margin-bottom: 0px" TextMode="MultiLine" Width="230px">
                    </telerik:RadTextBox>
                </td>
                <td>
                </td>
            </tr>
        </table>
        <asp:Button ID="btnSave" runat="server" Text="Save" />
    </fieldset>
</asp:Panel>
 
<asp:Panel runat="server" ID="EditPanel" Visible="false">
    <h2>Edit your campaigns</h2>
    <p>You may use the table below to edit/delete existing campaigns that currently exist on your system. <br /><b>Please be aware that if you delete a campaign ALL content and partner content will be deleted</b></p>
    <p>
        <asp:Label ID="EditFailureText" runat="server" ForeColor="Red" />
    </p>
    <fieldset>
        <legend>Edit existing campaigns</legend>
        <telerik:RadGrid ID="rgCampaigns" runat="server" AllowFilteringByColumn="True"
            AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
            GridLines="None">
            <MasterTableView EditMode="EditForms">
                <EditItemTemplate>
                </EditItemTemplate>
                <CommandItemSettings ExportToPdfText="Export to Pdf" />
                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                    <HeaderStyle Width="20px" />
                </RowIndicatorColumn>
                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                    <HeaderStyle Width="20px" />
                </ExpandCollapseColumn>
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" Display="False"
                        FilterControlAltText="Filter ID column" ReadOnly="true" HeaderText="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="UserId" Display="False"
                        FilterControlAltText="Filter UserId column" HeaderText="UserId" ReadOnly="True"
                        UniqueName="UserId">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Name"
                        FilterControlAltText="Filter Name column" HeaderText="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn AllowFiltering="False" DataField="Description"
                        FilterControlAltText="Filter Description column" HeaderText="Description"
                        UniqueName="Description">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="CreationDate"
                        FilterControlAltText="Filter CreationDate column" HeaderText="Date created"
                        UniqueName="CreationDate">
                    </telerik:GridBoundColumn>
                    <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column"
                        HeaderText="Edit">
                    </telerik:GridEditCommandColumn>
                    <telerik:GridButtonColumn CommandName="Delete"
                        FilterControlAltText="Filter Delete column" HeaderText="Delete" Text="Delete"
                        UniqueName="Delete">
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings EditFormType="Template">
                    <FormTemplate>
 
                    <fieldset class="register">
                        <legend>Edit campaign</legend>
                        <table>
                            <tr>
                                <td colspan="3"><asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="Edit" ForeColor="Red" DisplayMode="SingleParagraph" HeaderText="You must complete the fields marked with a *" runat="server" /></td>                       
                            </tr>
                            <tr>
                                <td>
                                    Name:</td>
                                <td>
                                    <telerik:RadTextBox ID="txtName" ValidationGroup="Edit" runat="server" Text='<%# Bind("Name") %>'
                                        EmptyMessage="Please type a name for the campaign" Width="230px">
                                    </telerik:RadTextBox>
                                </td>
                                <td>
                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="Edit" runat="server"
                                        ControlToValidate="txtName" ErrorMessage=""></asp:RequiredFieldValidator>
                                    <font color="red">*</font></td>
                            </tr>
                            <tr>
                                <td>
                                    Description</td>
                                <td>
                                    <telerik:RadTextBox ID="txtDescription" ValidationGroup="Edit" runat="server" Text='<%# Bind("Description") %>'
                                        EmptyMessage="Please type a description for your campaign" Rows="5"
                                        style="margin-bottom: 0px" TextMode="MultiLine" Width="230px">
                                    </telerik:RadTextBox>
                                </td>
                                <td>
                                </td>
                            </tr>
                        </table>
                        <asp:Button ID="btnUpdate" ValidationGroup="Edit" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                            runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'>
                        </asp:Button> <asp:Button ID="btnCancel" ValidationGroup="Edit" Text="Cancel" runat="server" CausesValidation="False"
                            CommandName="Cancel"></asp:Button>                           
                    </FormTemplate>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                    </EditColumn>
                </EditFormSettings>
            </MasterTableView>
            <FilterMenu EnableImageSprites="False">
            </FilterMenu>
            <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
            </HeaderContextMenu>
        </telerik:RadGrid>
    </fieldset>
</asp:Panel>

As you can see, I use the Ajax Manager to manage the datagrid on my form (including the EditFailureText for error messages). What I have found is that when I use the delete on the rgCampaigns grid, it executes and you see the AjaxLoadingPanel while it is refreshing. This is good and the new datasource is pulled back and displayed. Great :)
Now, when I edit the form, the same thing happens, which is great, but! The edit form stays open.... I have no idea why, but I believe it is something to do with the Ajax manager.

Any help with this would be appreciated.


4 Answers, 1 is accepted

Sort by
0
Jaymie
Top achievements
Rank 1
answered on 19 Jan 2011, 02:58 PM
oh and if it helps, this is my code behind file:

Imports BD.Business.CampaignBusiness
Imports BD.Common
 
Imports Telerik.Web.UI
 
Public Class Campaigns
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then rgCampaigns.Rebind()
    End Sub
 
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click
        EditFailureText.Text = "" ' Reset our edit failure text
 
        Dim cCampaign As New Campaign
        With cCampaign
            .Name = txtName.Text
            .Description = txtDescription.Text
            .UserId = Membership.GetUser.ProviderUserKey.ToString
        End With
        If NewCampaign(cCampaign) Then
            rgCampaigns.Rebind()
            CreateFailureText.Text = "Your campaign has been created. You may now create content for this campaign by using the menu above."
        Else
            CreateFailureText.Text = "Failed to create your campaign. Please contact the administrator for assistance."
        End If
    End Sub
 
    Protected Sub rgCampaigns_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles rgCampaigns.NeedDataSource
        Try
            Dim cCapaignCol As CampaignCollection = ReturnCampaigns(Membership.GetUser.ProviderUserKey.ToString)
            If cCapaignCol.Count > 0 Then EditPanel.Visible = True
            rgCampaigns.DataSource = cCapaignCol
        Catch ex As Exception
            EditPanel.Visible = False
        End Try
    End Sub
 
    Protected Sub rgCampaigns_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgCampaigns.ItemCommand
        Try
            Select Case e.CommandName
                Case "Update"
                    Dim item As GridEditFormItem = TryCast(e.Item, GridEditFormItem)
 
                    Dim cCampaign As New Campaign
                    With cCampaign
                        .ID = item("ID").Text
                        .UserId = item("UserId").Text
                        .Name = CType(item.FindControl("txtName"), RadTextBox).Text
                        .Description = CType(item.FindControl("txtDescription"), RadTextBox).Text
                        .CreationDate = CType(item.FindControl("dtCreated"), RadDatePicker).SelectedDate
                    End With
 
                    If Not EditCampaign(cCampaign) Then Throw New Exception("Failed to update the campaign (" & cCampaign.Name & ").")
                    EditFailureText.Text = "successfully updated the campaign (" & cCampaign.Name & ")."
                    rgCampaigns.Rebind()
                Case "Delete"
                    Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
                    Dim ID As Integer = item("ID").Text
                    Dim Name As String = item("Name").Text
 
                    If Not DeleteCampaign(ID) Then Throw New Exception("Failed to delete the campaign (" & Name & ").")
                    EditFailureText.Text = "successfully deleted the campaign (" & Name & ")."
            End Select
        Catch ex As Exception
            ' Got to love effeciency :)
            EditFailureText.Text = ex.ToString
        End Try
    End Sub
End Class
0
Elliott
Top achievements
Rank 2
answered on 19 Jan 2011, 08:27 PM
is the rgCampaigns.Rebind()
necessary / causing your problem?
0
Jaymie
Top achievements
Rank 1
answered on 20 Jan 2011, 02:41 PM
Hi,
No I added that line to see if that is why it wasn't disappearing.
0
Veli
Telerik team
answered on 24 Jan 2011, 07:46 AM
Hi Jaymie,

Your code seems fine. You can try removing the try-catch blocks to see if any exception is getting suppressed. Also, if you believe this might be an AJAX-related issue, you can disable or remove the RadAjaxManager from your page. Thus, your grid will make full page postbacks. If this issue cannot be reproduced without the AJAX manager, then it is an AJAX issue. Otherwise, it is not related to AJAX. Let me know what you are getting.

Veli
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Jaymie
Top achievements
Rank 1
Answers by
Jaymie
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Veli
Telerik team
Share this question
or