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

Refresh Grid data on INIT or LOAD

3 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 28 Mar 2010, 02:47 AM

Hello, and thanks ahead.

 

I am using RAD  ASP.NET AJAX  Q3 2009 NET 3.5
Visual Basic
Visual Studio 2008
 

I have an ASPX page with a RADGRID, a RADTABSTRIP, and a RADMULTIPAGE.

 

I have three pages in the multipage.

 

RADPAGEVIEW1  has a Form View

RADPAGEVIEW 2 has a Form View

RADPAGEVIEW 3 has a RADGRID

 

When the page loads, the first RADGRID acts as a master grid and when a user selects a row, all of the form views and the other RADGRIDS update perfectly. (Great product by the way.)

 

On RADPAGEVIEW 3 I have a button that opens a new window to add a record to a table. (It actually uploads an image to a folder and adds the details to the table. When the user has finished uploading the image, the SAVE button closes the window and refreshes the Parent with the Grids and Page Views. Using:


 Dim sbScript As New StringBuilder()  
        sbScript.Append("<script language=javascript>")  
        sbScript.Append("window.opener.document.forms[0].submit();")  
        sbScript.Append("self.close();")  
        sbScript.Append("</script>")  
        ScriptManager.RegisterStartupScript(MeMe.[GetType](), "@@@@MyPopUpScript", sbScript.ToString(), False)

 

What I would like to do, is when the page with the Grid and Page Views reloads, I would like for the data to refresh using the current data without passing anything from the closing window. Basically I want to just refresh the data and have it redisplay showing the new inserted record.

 

I am hoping it can be something simple like during INIT and just refresh the page.

 

Thanks in advance.



Code that calls the popup window


 

Imports System.Data  
Imports System.Data.SqlClient  
Imports Telerik.Web.UI  
Imports System.CodeDom  
Imports System.Web  
 
Partial Class terminal  
    Inherits System.Web.UI.Page  
 
 
    Protected Sub Page_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.PreRender  
        If RadGrid1.SelectedIndexes.Count = 0 Then 
            RadGrid1.SelectedIndexes.Add(0)  
        End If 
    End Sub 
 
    Protected Sub btn_AddVehicleImage_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btn_AddVehicleImage.Click  
        Dim IDProfilefleet As String = Request.QueryString("IDProfilefleet")  
        Dim IDProfileTerminal As String = Request.QueryString("IDProfileTerminal")  
        Dim IDProfileAccount As String = Request.QueryString("IDProfileAccount")  
        Dim IDVehicles As Label = CType(FormView2.FindControl("lbl_IDVeh"), Label)  
        Dim sbScript As New StringBuilder()  
 
        sbScript.Append("<script language='javascript'>")  
        sbScript.Append("window.open('")  
        sbScript.Append("../../imagemanager/imageupload.aspx?IDProfilefleet=" & IDProfilefleet & "&IDProfileTerminal=" & IDProfileTerminal & "&IDProfileAccount=" & IDProfileAccount & "&IDVehicles=" & IDVehicles.Text)  
        sbScript.Append("', 'CustomPopUp',")  
        sbScript.Append("'width=800, height=600, menubar=yes, resizable=yes');<")  
        sbScript.Append("/script>")  
 
        ' Make use ScriptManager to register the script  
        ScriptManager.RegisterStartupScript(MeMe.[GetType](), "@@@@MyPopUpScript", sbScript.ToString(), False)  
 
 
    End Sub 
 
 
 
End Class 
 
 
 
 


Code tha closes the popup window and refreshes parent page

Imports System.Data  
Imports System.Data.SqlClient  
Imports Radactive.WebControls.ILoad  
Imports Radactive.WebControls.ILoad.Configuration  
 
Partial Public Class ImageUpload_Detail  
    Inherits System.Web.UI.Page  
 
 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
 
        hf_IDProfileTerminal.Text = Request.QueryString("IDProfileTerminal")  
        hf_IDProfileAccount.Text = Request.QueryString("IDProfileAccount")  
        hf_IDProfileFleet.Text = Request.QueryString("IDProfileFleet")  
        hf_IDVehicles.Text = Request.QueryString("IDVehicles")  
 
        If (Not Me.IsPostBack) Then 
            ' Setup the I-Load configuration  
 
            ' Setup the control internal code / title  
            Me.CF_ImageUpload.Configuration.InternalCode = Director.Ex_E_101_ILoad1_InternalCode  
            Me.CF_ImageUpload.Configuration.Title = "Image Upload" 
            ' Setup the lightbox window mode  
            Me.CF_ImageUpload.WindowMode = ILoadWindowMode.Lightbox  
            ' Create a new image definition and add it to the I-Load configuration  
            Dim definition1 As WebImageDefinition = New WebImageDefinition("Default""Default")  
            Me.CF_ImageUpload.Configuration.WebImageDefinitions.Clear()  
            Me.CF_ImageUpload.Configuration.WebImageDefinitions.Add(definition1)  
 
 
            ' Automatic Image Resize (Image is resized proportianlly to a max size of 800x600)  
            Dim resize1 As WebImageResizeDefinition = New WebImageResizeDefinition("Thumbnail 1""Image")  
            definition1.ResizeDefinitions.Add(resize1)  
            resize1.Mode = Radactive.WebControls.ILoad.Core.Drawing.ImageResizeMode.Adaptive  
            resize1.AdaptiveMaxSize = New System.Drawing.Size(800, 600)  
 
 
            ' Automatic thumbanil #2 (Adaptive 100x100)  
            Dim resize2 As WebImageResizeDefinition = New WebImageResizeDefinition("Thumbnail 2""Thumb")  
            definition1.ResizeDefinitions.Add(resize2)  
            resize2.Mode = Radactive.WebControls.ILoad.Core.Drawing.ImageResizeMode.Adaptive  
            resize2.AdaptiveMaxSize = New System.Drawing.Size(100, 100)  
 
 
 
            ' Initialization  
            If (Not String.IsNullOrEmpty(Request.QueryString("IDImages"))) Then 
                ' UPDATE...  
 
 
 
                ' Load the database data  
                Using connection As SqlConnection = Director.GetNewOpenDbConnection()  
                    Using command As SqlCommand = connection.CreateCommand()  
                        command.CommandType = CommandType.Text  
                        command.CommandText = "SELECT [Title, FileName, ThumbnailName] FROM [CF_Images] WHERE [IDImages]=@IDImages" 
                        command.Parameters.AddWithValue("@Id"Me.RecordId)  
 
                        Using reader As SqlDataReader = command.ExecuteReader()  
                            If (reader.Read()) Then 
                                ' Record found  
 
 
                                Me.txtTitle.Text = Convert.ToString(reader("Title"))  
                            Else 
                                ' Record not found, return to list  
                                Response.Redirect("images.aspx"True)  
                                Return 
                            End If 
                        End Using  
                    End Using  
                End Using  
 
                ' Get the imageId  
                Dim imageId As String = Me.RecordId.ToString()  
 
                ' Check if Picture1 exists  
                If (WebImage.ExistsInFileSystem(Director.ImageRepositoryFolder, imageId)) Then 
                    ' Picture1 found...  
 
                    ' Load picture1  
                    Me.CF_ImageUpload.Value = WebImage.LoadFromFileSystem(Director.ImageRepositoryFolder, imageId)  
                End If 
            Else 
                ' INSERT...  
 
                Me.RecordId = 0  
 
 
            End If 
        End If 
 
    End Sub 
 
    ' Gets or sets the record id  
    Public Property RecordId() As Integer 
        Get 
            If (Not (Me.ViewState("RecordId"Is Nothing)) Then 
                Return DirectCast(Me.ViewState("RecordId"), Integer)  
            Else 
                Return 0  
            End If 
        End Get 
        Set(ByVal value As Integer)  
            Me.ViewState("RecordId") = value  
        End Set 
    End Property 
 
    Protected Sub cancelButton_Click(ByVal sender As ObjectByVal e As System.EventArgs)  
        ' Cancel - Return to list  
        Response.Redirect("imageupload.aspx")  
    End Sub 
 
    Protected Sub saveButton_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles saveButton.Click  
        ' Save the record  
        ' Validate   
        If (Not Me.IsValid) Then 
            Return 
        End If 
 
        If (Me.RecordId <> 0) Then 
            ' UPDATE...  
 
            Using connection As SqlConnection = Director.GetNewOpenDbConnection()  
                ' Update the record  
                Using command As SqlCommand = connection.CreateCommand()  
                    command.CommandType = CommandType.Text  
                    command.CommandText = "UPDATE [CF_Images] SET [Title]=@Title WHERE [IDImages]=@IDImages" 
                    command.Parameters.AddWithValue("@Title"Me.txtTitle.Text)  
                    command.Parameters.AddWithValue("@IDImages"Me.RecordId)  
 
                    command.ExecuteNonQuery()  
                End Using  
            End Using  
        Else 
            ' INSERT...  
 
            Using connection As SqlConnection = Director.GetNewOpenDbConnection()  
                ' Insert the new record  
                Using command As SqlCommand = connection.CreateCommand()  
                    command.CommandType = CommandType.Text  
                    command.CommandText = "INSERT INTO [CF_Images] ([Title]) VALUES (@Title)" 
                    command.Parameters.AddWithValue("@Title"Me.txtTitle.Text)  
 
                    command.ExecuteNonQuery()  
                End Using  
 
                ' Get the new record id  
                Using command As SqlCommand = connection.CreateCommand()  
                    command.CommandType = CommandType.Text  
                    command.CommandText = "SELECT @@IDENTITY" 
 
                    Me.RecordId = Convert.ToInt32(command.ExecuteScalar())  
                End Using  
            End Using  
        End If 
 
        ' Get the image id  
        Dim imageId As String = Me.RecordId.ToString()  
 
        ' Update image files in the file system  
        'WebImage.SynchronizeFileSystem(Me.picture1.Value, Director.ImageRepositoryFolder, imageId)  
        Me.CF_ImageUpload.SynchronizeFileSystem(Director.ImageRepositoryFolder, imageId)  
 
        ' Get the file names ---------------------------------------------------  
        Dim selectedImage_FileName As String 
        Dim thumbnail1_FileName As String 
        Dim thumbnail2_FileName As String 
        Dim UserID As String 
        Dim IDProfileTerminal As String 
        Dim IDProfileAccount As String 
        Dim IDProfileFleet As String 
        Dim IDVehicles As String 
 
 
 
        If (Not (CF_ImageUpload.Value Is Nothing)) Then 
            ' An image has been selected...  
            thumbnail1_FileName = CF_ImageUpload.Value.Resizes("Image").FileName  
            thumbnail2_FileName = CF_ImageUpload.Value.Resizes("Thumb").FileName  
            UserID = Session("UserID")  
            IDProfileTerminal = Request.QueryString("IDProfileTerminal")  
            IDProfileAccount = Request.QueryString("IDProfileAccount")  
            IDProfileFleet = Request.QueryString("IDProfileFleet")  
            IDVehicles = Request.QueryString("IDVehicles")  
 
        Else 
            ' No image selected  
            selectedImage_FileName = "" 
            thumbnail1_FileName = "" 
            thumbnail2_FileName = "" 
            UserID = "" 
            IDProfileTerminal = "" 
            IDProfileAccount = "" 
            IDProfileFleet = "" 
            IDVehicles = "" 
        End If 
        '----------------------------------------------------------------------  
 
        ' Save the file names -------------------------------------------------  
        Using connection As SqlConnection = Director.GetNewOpenDbConnection()  
            ' Update the record  
            Using command As SqlCommand = connection.CreateCommand()  
                command.CommandType = CommandType.Text  
                command.CommandText = "UPDATE [CF_Images] SET [FileName]=@thumbnail1_FileName, [ThumbnailName]=@thumbnail2_FileName, [UserID]=@UserID, [IDModifiedUser]=@IDModifiedUser, [IDProfileTerminal]=@IDProfileTerminal, [IDProfileAccount]=@IDProfileAccount, [IDProfileFleet]=@IDProfileFleet, [IDVehicles]=@IDVehicles WHERE [IDImages]=@IDImages" 
                command.Parameters.AddWithValue("@thumbnail1_FileName", thumbnail1_FileName)  
                command.Parameters.AddWithValue("@thumbnail2_FileName", thumbnail2_FileName)  
                command.Parameters.AddWithValue("@IDImages"Me.RecordId)  
                command.Parameters.AddWithValue("@UserID", UserID)  
                command.Parameters.AddWithValue("@IDModifiedUser", UserID)  
                command.Parameters.AddWithValue("@IDProfileTerminal", IDProfileTerminal)  
                command.Parameters.AddWithValue("@IDProfileAccount", IDProfileAccount)  
                command.Parameters.AddWithValue("@IDProfileFleet", IDProfileFleet)  
                command.Parameters.AddWithValue("@IDVehicles", IDVehicles)  
                command.ExecuteNonQuery()  
            End Using  
        End Using  
        '----------------------------------------------------------------------  
 
        ' All done - Return to list  
        Dim sbScript As New StringBuilder()  
        sbScript.Append("<script language=javascript>")  
        sbScript.Append("window.opener.document.forms[0].submit();")  
        sbScript.Append("self.close();")  
        sbScript.Append("</script>")  
        ScriptManager.RegisterStartupScript(MeMe.[GetType](), "@@@@MyPopUpScript", sbScript.ToString(), False)  
 
 
    End Sub 
 
    Protected Sub CF_ImageUpload_ValueChanged(ByVal sender As ObjectByVal e As Radactive.WebControls.ILoad.ILoadValueChangedEventArgs) Handles CF_ImageUpload.ValueChanged  
 
    End Sub 
 
End Class 
 
 
 

3 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 01 Apr 2010, 08:11 AM
Hello Allan,

In order to force the grid to display the updated data source record you should call its Rebind() method after you finish updating your data source.

I hope this helps,
Martin
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
Allan
Top achievements
Rank 2
answered on 02 Apr 2010, 05:48 PM

Thank you for the reply Martin.

 

I added RadAjax Manager to the grid in PageView3

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <ajaxsettings> 
            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">  
                <updatedcontrols> 
                    <telerik:AjaxUpdatedControl ControlID="rg_VehicleImages" /> 
                </updatedcontrols> 
            </telerik:AjaxSetting> 
        </ajaxsettings> 
</telerik:RadAjaxManager> 

And in the Code Behind I added

    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As ObjectByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest  
        rg_VehicleImages.Rebind()  
    End Sub 

However, this does not refresh the grid in PageView3.

Should this be placed in a Load or INIT?

Allan


0
Martin
Telerik team
answered on 08 Apr 2010, 08:58 AM
Hello Allan,

Could you please specify how you trigger the server-side AjaxRequest event? I would also suggest you to open a formal support ticket and send me a small runnable project demonstrating your scenario. This way I would be able to draw a clear picture of your case and provide you with more to-the-point resolution.

Regards,
Martin
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.
Tags
Grid
Asked by
Allan
Top achievements
Rank 2
Answers by
Martin
Telerik team
Allan
Top achievements
Rank 2
Share this question
or