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

Update after close window but not vCard

5 Answers 39 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 12 Aug 2014, 09:24 PM
Currently have a RadGrid that contains user information which they can click to edit the record or click on a button to download the vCard.  I would like it to refresh the grid after the user has closed the window.  However I do not need it to refresh if they click to download the vCard.  Can't seem to have it both ways at this time.  Any suggestions?  Tried removing the "Ajax" refresh but not positive it was working properly.

                            <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                                <script type="text/javascript">
                                    function onRequestStart(sender, args) {
                                        if (args.get_eventTarget().indexOf("vCard") >= 0)
                                            args.set_enableAjax(false);
                                    }
 
                                    function ShowEditForm(id, rowIndex) {
 
                                        var grid = $find("<%= _gridContacts.ClientID%>");
 
                                        var rowControl = grid.get_masterTableView().get_dataItems()[rowIndex].get_element();
                                        grid.get_masterTableView().selectItem(rowControl, true);
 
                                        window.radopen("Contacts.aspx?Contact_ID=" + id, "UserListDialog");
                                        return false;
                                    }
 
                                    function ShowInsertForm() {
                                        window.radopen("Contacts.aspx", "UserListDialog");
                                        return false;
                                    }
 
                                    function RowDblClick(sender, eventArgs) {
                                        window.radopen("Contacts.aspx?Contact_ID=" + eventArgs.getDataKeyValue("Contact_ID"), "UserListDialog");
                                    }
                                    function refreshGrid(arg) {
                                        if (!arg) {
                                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("Rebind");
                                        }
                                      else {
                                            $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("RebindAndNavigate");
                                        }
                                    }
                                </script>
                            </telerik:RadCodeBlock>
                            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
                                <AjaxSettings>
                                    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="_gridContacts" LoadingPanelID="gridLoadingPanel"></telerik:AjaxUpdatedControl>
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                    <telerik:AjaxSetting AjaxControlID="RadGrid1">
                                        <UpdatedControls>
                                            <telerik:AjaxUpdatedControl ControlID="_gridContacts" LoadingPanelID="gridLoadingPanel"></telerik:AjaxUpdatedControl>
                                        </UpdatedControls>
                                    </telerik:AjaxSetting>
                                </AjaxSettings>
                            </telerik:RadAjaxManager>
                        <telerik:RadAjaxLoadingPanel runat="server" ID="gridLoadingPanel"></telerik:RadAjaxLoadingPanel>
                        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
                        <ContentTemplate>
                        <telerik:RadGrid ID="_gridContacts" runat="server" AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
                             AllowMultiRowEdit="False" HeaderStyle-Font-Bold="true">
                            <MasterTableView CommandItemDisplay="None" DataKeyNames="Contact_ID" ClientDataKeyNames="Contact_ID">
                                <HeaderStyle Font-Bold="True" />
                                <Columns>
                                    <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                                        <HeaderStyle Width="20px"></HeaderStyle>
                                        <ItemTemplate>
                                            <asp:HyperLink ID="EditLink" runat="server" Text="Edit">
                                                <img style="border:0px;vertical-align:middle;" alt="" src="/Images/Edit.png"/>
                                            </asp:HyperLink>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridButtonColumn DataTextFormatString="Select {0}"
                                        ButtonType="ImageButton" UniqueName="vCard" HeaderText=" "
                                        ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
                                        ImageUrl="/images/vcard-icon.png" CommandName="VCard">
                                        <HeaderStyle Width="40px"></HeaderStyle>
                                    </telerik:GridButtonColumn>
                                    <telerik:GridTemplateColumn UniqueName="FullName" HeaderText="Name">
                                        <ItemTemplate>
                                            <%# DataBinder.Eval(Container.DataItem, "first_name")%> <%# DataBinder.Eval(Container.DataItem, "last_name")%>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn HeaderText="Title" UniqueName="Title" FilterControlAltText="Filter column column" DataField="Title">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text=""></ModelErrorMessage>
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn HeaderText="Phone" UniqueName="Phone1" FilterControlAltText="Filter column column" DataField="Phone1">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text=""></ModelErrorMessage>
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn UniqueName="Contact_Email" HeaderText="Contact Email">
                                        <ItemTemplate>
                                            <a href="mailto:<%# DataBinder.Eval(Container.DataItem, "Contact_Email")%>"><%# DataBinder.Eval(Container.DataItem, "Contact_Email")%></a>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridBoundColumn HeaderText="Previous CEO" UniqueName="Previous_CEO" FilterControlAltText="Filter column column" DataField="Previous_CEO">
                                        <ColumnValidationSettings>
                                            <ModelErrorMessage Text=""></ModelErrorMessage>
                                        </ColumnValidationSettings>
                                    </telerik:GridBoundColumn>
                                </Columns>
                            </MasterTableView>
                            <ClientSettings>
                                <Selecting AllowRowSelect="true"></Selecting>
                                <ClientEvents OnRowDblClick="RowDblClick"></ClientEvents>
                            </ClientSettings>
                        </telerik:RadGrid>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
<telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    <Windows>
        <telerik:RadWindow ID="UserListDialog" runat="server" Title="Editing record" Height="680px"
            Width="840px" Left="150px" ReloadOnShow="true" ShowContentDuringLoad="false"
            Modal="true" Behaviors="Close" OnClientClose="refreshGrid">
        </telerik:RadWindow>
    </Windows>
</telerik:RadWindowManager>

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Aug 2014, 05:32 AM
Hi Kurt Kluth,

Please take a look at the following demo on Grid - Window Editing. It shows how to refresh grid after any Update/Insert operation. You can also add the ButtonColumn to the Grid in this demo and it doesn't cause any postback. If this doesn't help,  please elaborate what download is happening on vCard and provide the code if possible.

Thanks,
Princy
0
Kurt Kluth
Top achievements
Rank 1
answered on 13 Aug 2014, 08:01 PM
Princy,

Thank you for the reply as it helped me make some adjustments on the refresh.  The problem is with the vCard link: it will download properly if that is the 1st thing you do after loading a record.  However if you were to update a value in the grid via the window, upon refresh of the grid, the download will no longer work.  It returns the following error:

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near 'BEGIN:VCARD

Private Sub _gridContacts_ItemCommand(sender As Object, e As GridCommandEventArgs) Handles _gridContacts.ItemCommand
        If e.CommandName = "VCard" Then
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)
            Dim DataKey As String = item.GetDataKeyValue("Contact_ID").ToString() 'e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Contact_ID").ToString()
            CreateVcard(DataKey)
        End If
    End Sub
 
    Private Sub _gridContacts_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles _gridContacts.ItemDataBound
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
            ScriptManager.GetCurrent(Page).RegisterPostBackControl(item("vCard").Controls(0))
 
            Dim ob As [Object] = item("Phone1").Text
            If Not Convert.IsDBNull(ob) Then
                Dim iParsedValue As Int64 = 0
                If item("Phone1").Text.Length = 10 Then
                    If Int64.TryParse(ob.ToString(), iParsedValue) Then
                        Dim cell As TableCell = item("Phone1")
                        cell.Text = [String].Format(System.Globalization.CultureInfo.CurrentCulture, "{0:(###) ###-####}", New Object() {iParsedValue})
                    End If
                Else 'length is greater than 10, has an extension
                    Dim sExtension As String()
                    sExtension = Split(item("Phone1").Text, " x. ")
                    If Int64.TryParse(sExtension(0).ToString, iParsedValue) Then
                        Dim cell As TableCell = item("Phone1")
                        cell.Text = [String].Format(System.Globalization.CultureInfo.CurrentCulture, "{0:(###) ###-####} x. {1}", iParsedValue, sExtension(1))
                    End If
                    End If
            End If
        End If
    End Sub
 
    Protected Sub _gridContacts_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles _gridContacts.ItemCreated
        If TypeOf e.Item Is GridDataItem Then
            Dim editLink As HyperLink = DirectCast(e.Item.FindControl("EditLink"), HyperLink)
            editLink.Attributes("href") = "javascript:void(0);"
            editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}','{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Contact_ID"), e.Item.ItemIndex)
        End If
    End Sub
 
    Sub CreateVcard(Contact_ID)
 
        Dim myCard = New vCard()
        Dim path As String, fName As String, lName As String
        Try
            oConn.Open()
            Dim ocmd As New SqlCommand("sp_getMarketingContact", oConn)
            ocmd.CommandType = CommandType.StoredProcedure
 
            With ocmd.Parameters
                .Add(New SqlParameter("@charter_num", Session("charter_num")))
                .Add(New SqlParameter("@ContactID", Contact_ID))
            End With
            reader = ocmd.ExecuteReader()
            If reader.HasRows Then
                reader.Read()
                fName = reader("first_name")
                lName = reader("last_name")
                myCard.FirstName = fName
                myCard.LastName = lName
                myCard.Organization = Me._CuName.Text
                myCard.JobTitle = reader("Title")
                myCard.CountryName = "USA"
                If Not reader("Phone1") Is DBNull.Value Then
                    myCard.Phone = reader("Phone1")
                End If
                If Not reader("contact_Fax") Is DBNull.Value Then
                    myCard.Fax = reader("contact_Fax")
                End If
                myCard.Email = reader("contact_Email")
            End If
            oConn.Close()
 
        Catch ex As Exception
            'Me._lblErrorMsg.Text = ex.Message
        Finally
            oConn.Close()
        End Try
        'send file to user
        Response.Clear()
 
        Response.ContentType = "text/vcard"
        Response.AppendHeader("content-disposition", "attachment;filename=" & LCase(fName & "_" & lName) & "_business_card.vcf")
        Response.Flush()
        Response.Write(myCard.ToString())
        Response.End()
 
    End Sub

Note and don't know if it is relevant but I removed the update panel from the code example in the first post.  If I left it in it would cause the following error upon closing the radwindow and refreshing the grid:

_getUpdatePanelID JavaScript runtime error: Unable to get property 'id' of undefined or null reference
















0
Kurt Kluth
Top achievements
Rank 1
answered on 15 Aug 2014, 07:17 PM
Princy,

I was hoping to edit my previous entry as I realized it was quite lengthy and I think I can simplify my request.  The example you provided about refreshing the grid after window editing works.  What if I now wanted to download a record from the grid into a text file?  It won't allow me to do it as it produces the error that the page is already "written". 

Any suggestions?

Message: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near 'BEGIN:VCARD
0
Kurt Kluth
Top achievements
Rank 1
answered on 04 Sep 2014, 03:31 PM
Princy,

Any suggestions from my last post?

Thanks
0
Kostadin
Telerik team
answered on 09 Sep 2014, 07:22 AM
Hi Kurt,

I would recommend you to check out the following blog post which elaborates more on the issue which you are facing and provides couple solutions to avoid it. Additionally I noticed that you are creating your own export functionality. If that is correct why don't you try exporting to CSV format which represent the grid content as a plain text?

Regards,
Kostadin
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
Kurt Kluth
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Kurt Kluth
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or