kyle goodfriend
Top achievements
Rank 2
kyle goodfriend
asked on 02 Jun 2011, 10:43 PM
I have a grid connected to an Access DB. I am moving the website to a shared environment. The new shared environment are virtual websites, so they are subfolders of another website on the server. After I got the permissions set and the RestoreOriginalRenderDelegate set to false on the page, things aren't working. The grid appears, but if I try to edit a record, the ajax progress bar appears, then goes away and nothing happens. Any suggestions on what to look at? I have no idea where to even start. It all works perfectly on the original server. If I can get some guidance, I can dig in to it and post code as necessary.
5 Answers, 1 is accepted
0
Hi kyle,
I suggest that you leave the default value for the RestoreOriginalRenderDelegate property and instead use of the approaches described in this article.
All the best,
Iana
the Telerik team
I suggest that you leave the default value for the RestoreOriginalRenderDelegate property and instead use of the approaches described in this article.
All the best,
Iana
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.
0
kyle goodfriend
Top achievements
Rank 2
answered on 14 Jun 2011, 12:19 AM
I have already done one of these actions. When I try to edit the grid, the progress window displays, then goes away with no action. I have added the tag to one, two, and all of the rad objects. If somebody could take a look, I would appreciate the help. I can't get it to work. I have other grids that work fine.
VB file
<%@ Page Language="VB" MasterPageFile="~/ClientAdmin/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_test_Default" Title="Untitled Page"%><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><asp:Content ID="Content2" ContentPlaceHolderID="cphHead" Runat="Server"> <style type="text/css"> .MyImageButton { cursor: hand; } .EditFormHeader td { font-size: 14px; padding: 4px !important; color: #0066cc; } </style></asp:Content><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <div> <telerik:RadAjaxManager RestoreOriginalRenderDelegate="false" ID="RadAjaxManager1" runat="server"> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="button1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> <AjaxSettings> <telerik:AjaxSetting AjaxControlID="RadGrid1"> <UpdatedControls> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/> </UpdatedControls> </telerik:AjaxSetting> </AjaxSettings> </telerik:RadAjaxManager> <telerik:RadAjaxLoadingPanel RestoreOriginalRenderDelegate="false" ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="15" Style="width: 320px;padding-top: 100px;" > <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /> </telerik:RadAjaxLoadingPanel> <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> //On insert and update buttons click temporarily disables ajax to perform upload actions function conditionalPostback(e, sender) { var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig"); if (sender.EventTarget.match(theRegexp)) { var upload = $find(window['UploadId']); //AJAX is disabled only if file is selected for upload if(upload.getFileInputs()[0].value != "") { sender.EnableAjax = false; } } } </script> </telerik:RadScriptBlock> <telerik:RadAjaxPanel RestoreOriginalRenderDelegate="false" ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback"> <telerik:RadGrid ID="RadGrid1" RestoreOriginalRenderDelegate="false" runat="server" DataSourceID="AccessDataSource1" AllowMultiRowSelection="true" Skin="Hay" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" OnItemCreated="RadGrid1_ItemCreated" AutoGenerateColumns="False" ShowStatusBar="True" Height="800" > <MasterTableView DataKeyNames="Id" Width="100%" TableLayout="Auto" CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false" CommandItemSettings-AddNewRecordText=" Add a new Album"> <Columns> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> <ItemStyle CssClass="MyImageButton" /> </telerik:GridEditCommandColumn> <telerik:GridCheckBoxColumn DataField="ActiveGroup" HeaderText="Active Group" SortExpression="ActiveGroup" UniqueName="ActiveGroupColumn" EditFormColumnIndex="1"> <HeaderStyle Width="50px" /> </telerik:GridCheckBoxColumn> <telerik:GridTemplateColumn HeaderText="Album Name" SortExpression="GroupName" UniqueName="GroupNameColumn" EditFormColumnIndex="1"> <ItemTemplate> <asp:Label runat="server" ID="lblGroupName" Text='<%# Eval("GroupName") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox Rows="1" Width="300" TextMode="SingleLine" MaxLength="200" runat="server" ID="tbGroupName" Text='<%# Bind("GroupName") %>'></asp:TextBox> <span style="color: Red">*</span><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbGroupName" ErrorMessage="Required" runat="server"></asp:RequiredFieldValidator><asp:TextBox Rows="1" Width="300" TextMode="SingleLine" Visible="false" MaxLength="200" runat="server" ID="txtExistingImage" Text='<%# Bind("Image") %>'></asp:TextBox> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Album Description" SortExpression="GroupDescription" UniqueName="GroupDescriptionColumn" EditFormColumnIndex="1"> <ItemTemplate> <asp:Label runat="server" ID="lblGroupDescription" Text='<%# Eval("GroupDescription") %>'></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox Rows="3" Width="300px" TextMode="multiline" runat="server" ID="tbGroupDescription" Text='<%# Bind("GroupDescription") %>'></asp:TextBox> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="Image" UniqueName="Upload" EditFormColumnIndex="1"> <ItemTemplate><asp:Image runat="server" ID="ImageThumbnail" AlternateText="No Image"ImageUrl='<%# DisplayImage(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath") & Eval("image"))%>' Style="border-width: 0px;" /> </ItemTemplate> <EditItemTemplate> <telerik:RadUpload ID="RadUpload1" runat="server" InitialFileInputsCount="1" MaxFileInputsCount="1" ControlObjectsVisibility="None" MaxFileSize="8000000" AllowedFileExtensions=".jpg" TargetFolder="" /> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="" SortExpression="ImageCount" UniqueName="ImageCountColumn"> <ItemTemplate> <asp:Hyperlink ID="lnkAddImages" runat="server"><%#"Add Images"%></asp:Hyperlink> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn HeaderText="" SortExpression="ImageCount" UniqueName="ImageCountColumn"> <ItemTemplate> <asp:Hyperlink ID="lnkEditImages" runat="server"><%#"Edit Images"%></asp:Hyperlink> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridButtonColumn ConfirmText="Do you want to delete this album?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> </telerik:GridButtonColumn> </Columns> <EditFormSettings ColumnNumber="2" CaptionDataField="GroupName" CaptionFormatString="Edit properties of Group {0}"> <FormTableItemStyle HorizontalAlign="Left" Wrap="True"></FormTableItemStyle> <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle> <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="LightGoldenrodYellow" Width="100%" /> <FormTableStyle CellSpacing="0" CellPadding="2" BackColor="LightGoldenrodYellow" /> <FormTableAlternatingItemStyle Wrap="True"></FormTableAlternatingItemStyle> <EditColumn ButtonType="PushButton" InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"> </EditColumn> <FormTableButtonRowStyle HorizontalAlign="left" CssClass=""></FormTableButtonRowStyle> </EditFormSettings> </MasterTableView> <ClientSettings AllowRowsDragDrop="true"> <Selecting EnableDragToSelectRows="true" AllowRowSelect="true" /> <Scrolling AllowScroll="true" /> </ClientSettings> </telerik:RadGrid></telerik:RadAjaxPanel> <asp:Label ID="lblInfo" runat="server" Text=""></asp:Label> </div> <asp:Button ID="Button1" runat="server" Text="Refresh Online Photo Gallery" style="margin-top:10px;" /> <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/ImageGallery.mdb" SelectCommand="SELECT tbGroups.ID, tbGroups.GroupName, tbGroups.GroupDescription,tbGroups.ActiveGroup, tbGroups.Image, Count(tbImages.ID) AS ImageCount FROM tbGroups LEFT JOIN tbImages ON tbGroups.ID = tbImages.Group GROUP BY tbGroups.ID, tbGroups.ActiveGroup, tbGroups.GroupName, tbGroups.GroupDescription, tbGroups.Image, tbGroups.SortId ORDER BY tbGroups.SortId;" DeleteCommand="DELETE FROM [tbGroups] WHERE [Id] = ?" UpdateCommand="UPDATE [tbGroups] SET [GroupName] = ?, [GroupDescription] = ?,[ActiveGroup] = ?, [Image] = ? WHERE [Id] = ?" InsertCommand="INSERT INTO [tbGroups] ([GroupName],[GroupDescription],[Image],[SortId]) VALUES (@GroupName,@GroupDescription,@Image,@SortId)" > <DeleteParameters> <asp:Parameter Name="Id" Type="Int32" /> </DeleteParameters> <UpdateParameters> <asp:Parameter Name="GroupName" Type="String" /> <asp:Parameter Name="GroupDescription" Type="String" /> <asp:Parameter Name="ActiveGroup" Type="Boolean" /> <asp:SessionParameter SessionField="ImageInsert" Name="Image" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="GroupName" Type="String" /> <asp:Parameter Name="GroupDescription" Type="String" /> <asp:SessionParameter SessionField="ImageInsert" Name="Image" Type="String" /> <asp:SessionParameter SessionField="SortInsert" Name="SortId" Type="String" /> </InsertParameters> </asp:AccessDataSource> <telerik:RadWindowManager RestoreOriginalRenderDelegate="false" ID="RadWindowManager1" runat="server" Skin="Vista"> <Windows> <telerik:RadWindow Behaviors="None" Skin="Hay" ID="UserListDialog" runat="server" Title="Group/Image Editor" Height="600px" Width="900px" Left="150px" ReloadOnShow="True" ShowContentDuringLoad="false" Modal="true" /> </Windows> </telerik:RadWindowManager> </asp:Content>Imports SystemImports System.Collections.GenericImports System.ConfigurationImports System.DataImports System.Data.CommonImports System.Data.SqlClientImports System.Data.OleDbImports System.Web.UIImports Telerik.Web.UIImports System.IOImports System.Drawing.ImagingImports System.DrawingImports System.XmlImports System.TextPartial Class _test_Default Inherits System.Web.UI.Page Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.DataBound If Not String.IsNullOrEmpty(gridMessage) Then DisplayMessage(gridMessage) End If End Sub Protected Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand 'System.Configuration.ConfigurationManager.AppSettings("RootImagePath") End Sub Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand If validFilesUploaded(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) = False Then e.Canceled = True Exit Sub End If Session("SortInsert") = Me.RadGrid1.Items.Count + 1 InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) End Sub Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand End Sub Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated If TypeOf e.Item Is GridDataItem Then Dim editLink As HyperLink = DirectCast(e.Item.FindControl("lnkEditImages"), HyperLink) editLink.Attributes("href") = "#" 'editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID")) 'editLink.Attributes("onclick") = [String].Format("alert('{0}{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex) editLink.Attributes("onclick") = [String].Format("window.radopen('EditImages.aspx?Group={0}&GroupName={2}', 'UserListDialog')", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex, e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("GroupName"), e.Item.ItemIndex) Dim addLink As HyperLink = DirectCast(e.Item.FindControl("lnkAddImages"), HyperLink) addLink.Attributes("href") = "#" 'editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID")) 'editLink.Attributes("onclick") = [String].Format("alert('{0}{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex) addLink.Attributes("onclick") = [String].Format("window.radopen('UploadImage.aspx?GroupID={0}', 'UserListDialog')", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex) End If End Sub Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then Dim upload As RadUpload = DirectCast(e.Item.FindControl("RadUpload1"), RadUpload) RadAjaxPanel1.ResponseScripts.Add(String.Format("window['UploadId'] = '{0}';", upload.ClientID)) End If End Sub Protected Sub RadGrid1_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles RadGrid1.ItemDeleted ' Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) ' Dim id As String = item.GetDataKeyValue("ProductID").ToString() End Sub Protected Sub RadGrid1_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted If Not e.Exception Is Nothing Then e.ExceptionHandled = True e.KeepInInsertMode = True SetMessage("The album cannot be inserted. Reason: " + e.Exception.Message) Else SetMessage("The album was added!") End If 'MsgBox(e.Exception.ToString) End Sub Protected Sub RadGrid1_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles RadGrid1.ItemUpdated Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) If Not e.Exception Is Nothing Then e.KeepInEditMode = True e.ExceptionHandled = True SetMessage("The album cannot be updated. Reason: " + e.Exception.Message) MsgBox(e.Exception.ToString) Else SetMessage("The album was updated!") End If End Sub Private Sub DisplayMessage(ByVal text As String) RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text))) End Sub Private Sub SetMessage(ByVal message As String) gridMessage = message End Sub Private gridMessage As String = Nothing Protected Sub RadGrid1_RowDrop(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDragDropEventArgs) Handles RadGrid1.RowDrop 'lblInfo.Text = lblInfo.Text & ":<br/>" & draggedItem.GetDataKeyValue("ID") 'Dim ordersToMove As New List(Of Order)() Dim dblCt As Double = 0.01 'If e.DraggedItems.Count > 1 Then dblCt += 1 Dim iDestination As Integer = e.DestDataItem.ItemIndex For Each draggedItem As GridDataItem In e.DraggedItems lblInfo.Text = lblInfo.Text & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & _ " moved to " & DirectCast(e.DestDataItem.GetDataKeyValue("Id"), Integer) & _ "-" If draggedItem.ItemIndex < iDestination Then Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iDestination + dblCt + 1 & " WHERE ID = " & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & ";" Me.AccessDataSource1.Update() lblInfo.Text = lblInfo.Text & iDestination + dblCt + 1 & "<br/>" Else Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iDestination + dblCt & " WHERE ID = " & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & ";" Me.AccessDataSource1.Update() lblInfo.Text = lblInfo.Text & iDestination + dblCt & "<br/>" End If dblCt += 0.01 ' 'use if moving up 'do until index number 'then add one to every sort number there after ' change sort order of ID of dropped item to index+1 'use if moving down 'do until index number-1 'then subtract one to every sort number there after ' change sort order of ID of dropped item to index+1 Next Dim connString As String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _ Server.MapPath("/app_data/imagegallery.mdb") Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'open the connection 'Specify our SQL statement Dim strSQL As String = "SELECT * FROM [tbGroups] ORDER BY SortId" 'Create the Command object Dim objCommand As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) ' Set an OleDbDataReader to the command's results Dim objDataReader As OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) Dim iCt As Integer = 1 While objDataReader.Read() Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iCt & " WHERE ID = " & objDataReader("ID") & ";" Me.AccessDataSource1.Update() iCt += 1 ' e.g.: str = objDataReader("DepartmentName") End While objDataReader.Close() objConnection.Close() objDataReader = Nothing objConnection = Nothing objCommand = Nothing End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Me.RadAjaxManager1.Alert(UpdateXML()) End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand ' Session("SortInsert") = e.Item.DataItem("image").ToString If validFilesUploaded(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) = False Then e.Canceled = True Exit Sub End If Session("ImageInsert") = DirectCast(e.Item.FindControl("txtExistingImage"), TextBox).Text.ToString ' InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) End Sub Function validFilesUploaded(ByVal currentUpload As RadUpload) As Boolean If currentUpload.InvalidFiles.Count > 0 Then Me.RadAjaxManager1.Alert("The file you selected is invalid. Please select a JPG file that is under 8 gig in size.") validFilesUploaded = False Else validFilesUploaded = True End If End Function Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload) ' Session("ImageInsert") = "" 'resize and save image ' Set image quality If currentUpload.UploadedFiles.Count > 0 Then Dim intQuality As Integer = System.Configuration.ConfigurationManager.AppSettings("ImageQuality") 'set path currentUpload.TargetFolder = System.Configuration.ConfigurationManager.AppSettings("RootImagePath") Dim abpath As String Dim validFile As UploadedFile 'set time for file name Dim idTime As String = DateTime.Now.ToString("yy_MM_dd") & "_" & DateTime.Now.Hour() & DateTime.Now.Minute() & DateTime.Now.Second abpath = Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension()) 'save file as temp file before altering currentUpload.UploadedFiles(0).SaveAs(abpath, True) Dim maxHeight As Int16 Dim maxWidth As Int16 Dim originalimg, originalimg1, thumb As System.Drawing.Image Dim strFileName, strFileName1 As String Dim width, height, oheight, owidth As Integer Dim width1, height1 As Integer Dim rootpath As String Dim strFilePath As String Dim strFilePath1 As String Dim strFolder As String originalimg = originalimg.FromFile(abpath) ' Fetch User Filename 'get original dimensions so ratio will remain when resizing oheight = originalimg.Height owidth = originalimg.Width Dim iHeight As Int16 Dim iWidth As Int16 Dim imageType As String 'set max hieght iHeight = System.Configuration.ConfigurationManager.AppSettings("AlbumMaxHeight") iWidth = iHeight * owidth / oheight ' Assign default height. If oheight > System.Configuration.ConfigurationManager.AppSettings("AlbumMaxHeight") Then iWidth = System.Configuration.ConfigurationManager.AppSettings("AlbumMaxWidth") iHeight = iWidth * oheight / owidth End If imageType = System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath") maxHeight = iHeight maxWidth = iWidth originalimg.Dispose() 'This method draws a new blank image first Dim bm As Bitmap = CType(System.Drawing.Image.FromFile(Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension())), Bitmap) Dim resized As New Bitmap(iWidth, iHeight) Dim g As Graphics = Graphics.FromImage(resized) g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel) g.Dispose() 'Get the list of available encoders Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders() 'find the encoder with the image/jpeg mime-type Dim iciInfo As ImageCodecInfo Dim item As ImageCodecInfo For Each item In codecs If (item.MimeType = "image/jpeg") Then iciInfo = item Next Dim ep As EncoderParameters = New EncoderParameters ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, intQuality) 'strFilePath = Server.MapPath("/images/photogallery/test/" & Me.ListBox1.SelectedItem.Text.ToString & "/clip") & "\" & strFileName ' Root Folder + FileName Try resized.Save(Path.Combine(Server.MapPath(currentUpload.TargetFolder) + imageType, idTime & currentUpload.UploadedFiles(0).GetExtension()), iciInfo, ep) 'set parameter for image name Session("ImageInsert") = idTime & currentUpload.UploadedFiles(0).GetExtension() Me.AccessDataSource1.UpdateCommand = "UPDATE [tbGroups] SET [GroupName] = ?, [GroupDescription] = ?,[ActiveGroup] = ?, [Image] = ? WHERE [Id] = ?" Catch ex As Exception Response.Write(ex.Message) End Try bm.Dispose() resized.Dispose() File.Delete(Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension())) Else 'Me.AccessDataSource1.UpdateParameters( 'Me.RadAjaxManager1.Alert(Session("ImageInsert")) ' Me.AccessDataSource1.UpdateCommand = "UPDATE [tbGroups] SET [GroupName] = @GroupName, [GroupDescription] = @GroupDescription, [ActiveGroup] = @ActiveGroup, [Image] = @original_Image WHERE [Id] = @Id" ' Me.RadAjaxManager1.Alert(Me.AccessDataSource1.UpdateCommand) 'Session("ImageInsert") = Me.AccessDataSource1.UpdateParameters("original_Image") End If End Sub Function DisplayImage(ByVal sImage As String) As String If File.Exists(Server.MapPath(sImage)) Then DisplayImage = sImage Else DisplayImage = "/images/noimage.gif" End If End Function Function UpdateXML() As String Dim settings As New XmlWriterSettings settings.Indent = True settings.Encoding = Encoding.UTF8 settings.ConformanceLevel = ConformanceLevel.Auto settings.Indent = True settings.IndentChars = ControlChars.Tab settings.NewLineHandling = NewLineHandling.Entitize settings.NewLineChars = vbCrLf settings.NewLineHandling = NewLineHandling.Entitize settings.NewLineOnAttributes = True settings.OmitXmlDeclaration = True Dim iCounter As Integer = 1 Dim xmlDoc As String = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("ImagesXMLLocation") & "/Images.xml") Dim writer As XmlWriter writer = XmlWriter.Create(xmlDoc, settings) writer.WriteStartDocument() Try Dim connString As String connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _ Server.MapPath("/app_data/imagegallery.mdb") Dim objConnection As OleDbConnection objConnection = New OleDbConnection(connString) objConnection.Open() 'open the connection 'Specify our SQL statement Dim strSQL As String = "SELECT * FROM [tbGroups] WHERE ActiveGroup = True ORDER BY SortId " 'Create the Command object Dim objCommand As OleDbCommand Dim objCommandDetail As OleDbCommand objCommand = New OleDbCommand(strSQL, objConnection) objCommandDetail = New OleDbCommand(strSQL, objConnection) ' Set an OleDbDataReader to the command's results Dim objDataReader As OleDbDataReader objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection) ' Set an OleDbDataReader to the command's results Dim objDataReaderDetail As OleDbDataReader 'Dim iCt As Integer = 1 writer.WriteStartElement("gallery") While objDataReader.Read() writer.WriteStartElement("album") writer.WriteAttributeString("id", iCounter.ToString) writer.WriteAttributeString("title", objDataReader("groupname").ToString) writer.WriteAttributeString("description", objDataReader("groupdescription").ToString) writer.WriteAttributeString("lgPath", System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("LargeImagePath")) writer.WriteAttributeString("tnPath", System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("ThumbImagePath")) writer.WriteAttributeString("tn", Path.Combine(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath"), objDataReader("image").ToString)) objCommandDetail = New OleDbCommand(strSQL, objConnection) objCommandDetail.CommandText = "SELECT * FROM tbImages WHERE [Group] = " & objDataReader("Id") objDataReaderDetail = objCommandDetail.ExecuteReader(CommandBehavior.CloseConnection) While objDataReaderDetail.Read writer.WriteStartElement("img") writer.WriteAttributeString("src", objDataReaderDetail("image").ToString) writer.WriteAttributeString("title", objDataReaderDetail("title").ToString) writer.WriteAttributeString("caption", objDataReaderDetail("caption").ToString) writer.WriteAttributeString("link", objDataReaderDetail("link").ToString) writer.WriteEndElement() End While 'objDataReaderDetail.Close() writer.WriteEndElement() iCounter += 1 End While writer.WriteEndDocument() writer.Close() objDataReader.Close() objConnection.Close() objDataReader = Nothing objConnection = Nothing objCommand = Nothing 'If System.IO.File.Exists(Server.MapPath("/Images.xml")) Then 'System.IO.File.Delete(Server.MapPath("/Images.xml")) 'End If' System.IO.File.Copy(Server.MapPath("/app_data/Images.xml"), Server.MapPath("/Images.xml")) UpdateXML = "Your Gallery has been updated. Most browsers save a website state locally when flash is used. For you to see the changes immediately, please delete your cached data. When using Internet Explorer, Go to Tools/Internet Options, and delete your Browser History/Internet Files." Catch ex As Exception 'writer.WriteEndElement() UpdateXML = "An error has occurred. Detail:" & ex.Message writer.Close() End Try End FunctionEnd Class0
kyle goodfriend
Top achievements
Rank 2
answered on 14 Jun 2011, 12:23 AM
I have already done one of these actions. When I try to edit the grid, the progress window displays, then goes away with no action. I have added the tag to one, two, and all of the rad objects. If somebody could take a look, I would appreciate the help. I can't get it to work. I have other grids that work fine.
VB file
<%@ Page Language="VB" MasterPageFile="~/ClientAdmin/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_test_Default" Title="Untitled Page"%><br><%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %><br> <br><asp:Content ID="Content2" ContentPlaceHolderID="cphHead" Runat="Server"><br> <style type="text/css"><br> .MyImageButton<br> {<br> cursor: hand;<br> }<br> .EditFormHeader td<br> {<br> font-size: 14px;<br> padding: 4px !important;<br> color: #0066cc;<br> }<br> </style><br></asp:Content><br><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><br> <br> <br> <div><br> <telerik:RadAjaxManager RestoreOriginalRenderDelegate="false" ID="RadAjaxManager1" runat="server"><br> <AjaxSettings><br> <telerik:AjaxSetting AjaxControlID="button1"><br> <UpdatedControls><br> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/><br> </UpdatedControls><br> </telerik:AjaxSetting><br> </AjaxSettings><br> <AjaxSettings><br> <telerik:AjaxSetting AjaxControlID="RadGrid1"><br> <UpdatedControls><br> <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"/><br> </UpdatedControls><br> </telerik:AjaxSetting><br> </AjaxSettings><br> </telerik:RadAjaxManager><br> <telerik:RadAjaxLoadingPanel RestoreOriginalRenderDelegate="false" ID="RadAjaxLoadingPanel1" runat="server" Height="75px" Width="75px" Transparency="15" Style="width: 320px;padding-top: 100px;"<br> ><br> <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>' style="border:0;" /><br> </telerik:RadAjaxLoadingPanel><br> <br> <br> <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"><br> <br> <script type="text/javascript"><br> //On insert and update buttons click temporarily disables ajax to perform upload actions<br> function conditionalPostback(e, sender)<br> {<br> var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");<br> if (sender.EventTarget.match(theRegexp))<br> {<br> var upload = $find(window['UploadId']);<br> <br> //AJAX is disabled only if file is selected for upload<br> if(upload.getFileInputs()[0].value != "")<br> {<br> sender.EnableAjax = false;<br> }<br> }<br> }<br> </script><br> <br> </telerik:RadScriptBlock><br> <br><telerik:RadAjaxPanel RestoreOriginalRenderDelegate="false" ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback"><br> <telerik:RadGrid ID="RadGrid1" RestoreOriginalRenderDelegate="false" runat="server" DataSourceID="AccessDataSource1" AllowMultiRowSelection="true" Skin="Hay"<br> AllowAutomaticDeletes="True"<br> AllowAutomaticInserts="True"<br> AllowAutomaticUpdates="True"<br> OnItemUpdated="RadGrid1_ItemUpdated"<br> OnItemDeleted="RadGrid1_ItemDeleted"<br> OnItemInserted="RadGrid1_ItemInserted"<br> OnItemCreated="RadGrid1_ItemCreated"<br> AutoGenerateColumns="False"<br> ShowStatusBar="True"<br> Height="800"<br> ><br> <MasterTableView DataKeyNames="Id" Width="100%" TableLayout="Auto"<br> CommandItemDisplay="TopAndBottom" AutoGenerateColumns="false"<br> CommandItemSettings-AddNewRecordText=" Add a new Album"><br> <Columns><br> <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"><br> <ItemStyle CssClass="MyImageButton" /><br> </telerik:GridEditCommandColumn><br> <br> <telerik:GridCheckBoxColumn DataField="ActiveGroup" HeaderText="Active Group" SortExpression="ActiveGroup"<br> UniqueName="ActiveGroupColumn" EditFormColumnIndex="1"><br> <HeaderStyle Width="50px" /><br> </telerik:GridCheckBoxColumn><br> <br> <br> <telerik:GridTemplateColumn HeaderText="Album Name" SortExpression="GroupName" UniqueName="GroupNameColumn"<br> EditFormColumnIndex="1"><br> <ItemTemplate><br> <asp:Label runat="server" ID="lblGroupName" Text='<%# Eval("GroupName") %>'></asp:Label><br> </ItemTemplate><br> <EditItemTemplate><br> <asp:TextBox Rows="1" Width="300" TextMode="SingleLine" MaxLength="200" runat="server" ID="tbGroupName" Text='<%# Bind("GroupName") %>'></asp:TextBox><br> <span style="color: Red">*</span><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="tbGroupName" ErrorMessage="Required" runat="server"></asp:RequiredFieldValidator><br> <br><asp:TextBox Rows="1" Width="300" TextMode="SingleLine" Visible="false" MaxLength="200" runat="server" ID="txtExistingImage" Text='<%# Bind("Image") %>'></asp:TextBox><br> <br> <br> </EditItemTemplate><br> </telerik:GridTemplateColumn><br> <br> <telerik:GridTemplateColumn HeaderText="Album Description" SortExpression="GroupDescription" UniqueName="GroupDescriptionColumn"<br> EditFormColumnIndex="1"><br> <ItemTemplate><br> <asp:Label runat="server" ID="lblGroupDescription" Text='<%# Eval("GroupDescription") %>'></asp:Label><br> </ItemTemplate><br> <EditItemTemplate><br> <asp:TextBox Rows="3" Width="300px" TextMode="multiline" runat="server" ID="tbGroupDescription" Text='<%# Bind("GroupDescription") %>'></asp:TextBox><br> </EditItemTemplate><br> </telerik:GridTemplateColumn><br> <br> <br> <telerik:GridTemplateColumn HeaderText="Image" UniqueName="Upload" EditFormColumnIndex="1"><br> <ItemTemplate><br><asp:Image runat="server" ID="ImageThumbnail" AlternateText="No Image"<br>ImageUrl='<%# DisplayImage(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath") & Eval("image"))%>' Style="border-width: 0px;" /><br> </ItemTemplate><br> <EditItemTemplate><br> <telerik:RadUpload ID="RadUpload1" runat="server" InitialFileInputsCount="1" MaxFileInputsCount="1"<br> ControlObjectsVisibility="None" MaxFileSize="8000000" AllowedFileExtensions=".jpg"<br> TargetFolder="" /><br> </EditItemTemplate><br> </telerik:GridTemplateColumn><br> <br> <telerik:GridTemplateColumn HeaderText="" SortExpression="ImageCount" UniqueName="ImageCountColumn"><br> <ItemTemplate><br> <asp:Hyperlink ID="lnkAddImages" runat="server"><%#"Add Images"%></asp:Hyperlink><br> <br> </ItemTemplate><br> </telerik:GridTemplateColumn><br> <telerik:GridTemplateColumn HeaderText="" SortExpression="ImageCount" UniqueName="ImageCountColumn"><br> <ItemTemplate><br> <asp:Hyperlink ID="lnkEditImages" runat="server"><%#"Edit Images"%></asp:Hyperlink><br> <br> </ItemTemplate><br> </telerik:GridTemplateColumn><br> <br> <telerik:GridButtonColumn ConfirmText="Do you want to delete this album?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton"<br> CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"><br> <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /><br> </telerik:GridButtonColumn><br> <br> <br> <br> </Columns><br> <EditFormSettings ColumnNumber="2" CaptionDataField="GroupName" CaptionFormatString="Edit properties of Group {0}"><br> <FormTableItemStyle HorizontalAlign="Left" Wrap="True"></FormTableItemStyle><br> <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle><br> <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="LightGoldenrodYellow"<br> Width="100%" /><br> <FormTableStyle CellSpacing="0" CellPadding="2" BackColor="LightGoldenrodYellow" /><br> <FormTableAlternatingItemStyle Wrap="True"></FormTableAlternatingItemStyle><br> <EditColumn ButtonType="PushButton"<br> InsertText="Insert Order" UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit"><br> </EditColumn><br> <FormTableButtonRowStyle HorizontalAlign="left" CssClass=""></FormTableButtonRowStyle><br> </EditFormSettings><br> </MasterTableView><br> <ClientSettings AllowRowsDragDrop="true"><br> <Selecting EnableDragToSelectRows="true" AllowRowSelect="true" /><br> <Scrolling AllowScroll="true" /><br> </ClientSettings><br> </telerik:RadGrid><br></telerik:RadAjaxPanel><br> <br> <br> <br> <br> <br> <asp:Label ID="lblInfo" runat="server" Text=""></asp:Label><br> </div><br> <asp:Button ID="Button1" runat="server" Text="Refresh Online Photo Gallery" style="margin-top:10px;" /><br> <asp:AccessDataSource ID="AccessDataSource1" runat="server"<br> DataFile="~/App_Data/ImageGallery.mdb"<br> SelectCommand="SELECT tbGroups.ID, tbGroups.GroupName, tbGroups.GroupDescription,tbGroups.ActiveGroup, tbGroups.Image, Count(tbImages.ID) AS ImageCount FROM tbGroups LEFT JOIN tbImages ON tbGroups.ID = tbImages.Group GROUP BY tbGroups.ID, tbGroups.ActiveGroup, tbGroups.GroupName, tbGroups.GroupDescription, tbGroups.Image, tbGroups.SortId ORDER BY tbGroups.SortId;"<br> DeleteCommand="DELETE FROM [tbGroups] WHERE [Id] = ?"<br> UpdateCommand="UPDATE [tbGroups] SET [GroupName] = ?, [GroupDescription] = ?,[ActiveGroup] = ?, [Image] = ? WHERE [Id] = ?" <br> InsertCommand="INSERT INTO [tbGroups] ([GroupName],[GroupDescription],[Image],[SortId]) VALUES (@GroupName,@GroupDescription,@Image,@SortId)"<br> ><br> <DeleteParameters><br> <asp:Parameter Name="Id" Type="Int32" /><br> </DeleteParameters><br> <UpdateParameters><br> <asp:Parameter Name="GroupName" Type="String" /><br> <asp:Parameter Name="GroupDescription" Type="String" /><br> <asp:Parameter Name="ActiveGroup" Type="Boolean" /><br> <asp:SessionParameter SessionField="ImageInsert" Name="Image" Type="String" /><br> </UpdateParameters><br> <InsertParameters><br> <asp:Parameter Name="GroupName" Type="String" /><br> <asp:Parameter Name="GroupDescription" Type="String" /><br> <asp:SessionParameter SessionField="ImageInsert" Name="Image" Type="String" /><br> <asp:SessionParameter SessionField="SortInsert" Name="SortId" Type="String" /><br> </InsertParameters><br> </asp:AccessDataSource><br> <br> <br> <telerik:RadWindowManager RestoreOriginalRenderDelegate="false" ID="RadWindowManager1" runat="server" Skin="Vista"><br> <Windows><br> <telerik:RadWindow Behaviors="None"<br> Skin="Hay"<br> ID="UserListDialog" runat="server" Title="Group/Image Editor" Height="600px"<br> Width="900px" Left="150px" ReloadOnShow="True" ShowContentDuringLoad="false" Modal="true" /><br> </Windows><br> </telerik:RadWindowManager><br> <br></asp:Content>VB file
Imports System<br>Imports System.Collections.Generic<br>Imports System.Configuration<br>Imports System.Data<br>Imports System.Data.Common<br>Imports System.Data.SqlClient<br>Imports System.Data.OleDb<br>Imports System.Web.UI<br>Imports Telerik.Web.UI<br>Imports System.IO<br>Imports System.Drawing.Imaging<br>Imports System.Drawing<br>Imports System.Xml<br>Imports System.Text<br> <br> <br>Partial Class _test_Default<br> Inherits System.Web.UI.Page<br> <br> Protected Sub RadGrid1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.DataBound<br> If Not String.IsNullOrEmpty(gridMessage) Then<br> DisplayMessage(gridMessage)<br> End If<br> End Sub<br> <br> Protected Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand<br> 'System.Configuration.ConfigurationManager.AppSettings("RootImagePath")<br> End Sub<br> <br> Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.InsertCommand<br> If validFilesUploaded(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) = False Then<br> e.Canceled = True<br> Exit Sub<br> <br> End If<br> <br> Session("SortInsert") = Me.RadGrid1.Items.Count + 1<br> InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))<br> End Sub<br> <br> Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand<br> <br> End Sub<br> <br> Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated<br> If TypeOf e.Item Is GridDataItem Then<br> Dim editLink As HyperLink = DirectCast(e.Item.FindControl("lnkEditImages"), HyperLink)<br> editLink.Attributes("href") = "#"<br> 'editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID"))<br> 'editLink.Attributes("onclick") = [String].Format("alert('{0}{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex)<br> editLink.Attributes("onclick") = [String].Format("window.radopen('EditImages.aspx?Group={0}&GroupName={2}', 'UserListDialog')", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex, e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("GroupName"), e.Item.ItemIndex)<br> <br> Dim addLink As HyperLink = DirectCast(e.Item.FindControl("lnkAddImages"), HyperLink)<br> addLink.Attributes("href") = "#"<br> 'editLink.Attributes("onclick") = [String].Format("return ShowEditForm('{0}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ID"))<br> 'editLink.Attributes("onclick") = [String].Format("alert('{0}{1}');", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex)<br> addLink.Attributes("onclick") = [String].Format("window.radopen('UploadImage.aspx?GroupID={0}', 'UserListDialog')", e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("Id"), e.Item.ItemIndex)<br> End If<br> End Sub<br> <br> Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound<br> If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then<br> Dim upload As RadUpload = DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)<br> RadAjaxPanel1.ResponseScripts.Add(String.Format("window['UploadId'] = '{0}';", upload.ClientID))<br> End If<br> End Sub<br> <br> Protected Sub RadGrid1_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles RadGrid1.ItemDeleted<br> ' Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)<br> ' Dim id As String = item.GetDataKeyValue("ProductID").ToString()<br> End Sub<br> <br> Protected Sub RadGrid1_ItemInserted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridInsertedEventArgs) Handles RadGrid1.ItemInserted<br> If Not e.Exception Is Nothing Then<br> e.ExceptionHandled = True<br> e.KeepInInsertMode = True<br> SetMessage("The album cannot be inserted. Reason: " + e.Exception.Message)<br> Else<br> SetMessage("The album was added!")<br> End If<br> 'MsgBox(e.Exception.ToString)<br> <br> <br> <br> End Sub<br> <br> Protected Sub RadGrid1_ItemUpdated(ByVal source As Object, ByVal e As Telerik.Web.UI.GridUpdatedEventArgs) Handles RadGrid1.ItemUpdated<br> Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)<br> If Not e.Exception Is Nothing Then<br> e.KeepInEditMode = True<br> e.ExceptionHandled = True<br> SetMessage("The album cannot be updated. Reason: " + e.Exception.Message)<br> MsgBox(e.Exception.ToString)<br> Else<br> SetMessage("The album was updated!")<br> End If<br> <br> End Sub<br> <br> Private Sub DisplayMessage(ByVal text As String)<br> RadGrid1.Controls.Add(New LiteralControl(String.Format("<span style='color:red'>{0}</span>", text)))<br> End Sub<br> <br> Private Sub SetMessage(ByVal message As String)<br> gridMessage = message<br> End Sub<br> <br> Private gridMessage As String = Nothing<br> <br> <br> Protected Sub RadGrid1_RowDrop(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridDragDropEventArgs) Handles RadGrid1.RowDrop<br> <br> 'lblInfo.Text = lblInfo.Text & ":<br/>" & draggedItem.GetDataKeyValue("ID")<br> 'Dim ordersToMove As New List(Of Order)()<br> Dim dblCt As Double = 0.01<br> 'If e.DraggedItems.Count > 1 Then dblCt += 1<br> Dim iDestination As Integer = e.DestDataItem.ItemIndex<br> For Each draggedItem As GridDataItem In e.DraggedItems<br> lblInfo.Text = lblInfo.Text & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & _<br> " moved to " & DirectCast(e.DestDataItem.GetDataKeyValue("Id"), Integer) & _<br> "-"<br> If draggedItem.ItemIndex < iDestination Then<br> Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text<br> Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iDestination + dblCt + 1 & " WHERE ID = " & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & ";"<br> Me.AccessDataSource1.Update()<br> lblInfo.Text = lblInfo.Text & iDestination + dblCt + 1 & "<br/>"<br> Else<br> Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text<br> Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iDestination + dblCt & " WHERE ID = " & DirectCast(draggedItem.GetDataKeyValue("Id"), Integer) & ";"<br> Me.AccessDataSource1.Update()<br> lblInfo.Text = lblInfo.Text & iDestination + dblCt & "<br/>"<br> End If<br> dblCt += 0.01<br> <br> <br> '<br> 'use if moving up<br> 'do until index number<br> 'then add one to every sort number there after<br> ' change sort order of ID of dropped item to index+1<br> <br> 'use if moving down<br> 'do until index number-1<br> 'then subtract one to every sort number there after<br> ' change sort order of ID of dropped item to index+1<br> Next<br> <br> <br> <br> Dim connString As String<br> connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _<br> Server.MapPath("/app_data/imagegallery.mdb")<br> <br> Dim objConnection As OleDbConnection<br> objConnection = New OleDbConnection(connString)<br> objConnection.Open() 'open the connection<br> 'Specify our SQL statement<br> Dim strSQL As String = "SELECT * FROM [tbGroups] ORDER BY SortId"<br> <br> 'Create the Command object<br> Dim objCommand As OleDbCommand<br> objCommand = New OleDbCommand(strSQL, objConnection)<br> <br> ' Set an OleDbDataReader to the command's results<br> Dim objDataReader As OleDbDataReader<br> objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)<br> <br> Dim iCt As Integer = 1<br> While objDataReader.Read()<br> Me.AccessDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text<br> Me.AccessDataSource1.UpdateCommand = "Update tbGroups SET [SortId] = " & iCt & " WHERE ID = " & objDataReader("ID") & ";"<br> Me.AccessDataSource1.Update()<br> iCt += 1<br> ' e.g.: str = objDataReader("DepartmentName")<br> End While<br> <br> objDataReader.Close()<br> objConnection.Close()<br> objDataReader = Nothing<br> objConnection = Nothing<br> objCommand = Nothing<br> <br> <br> <br> <br> <br> End Sub<br> <br> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click<br> <br> Me.RadAjaxManager1.Alert(UpdateXML())<br> <br> <br> <br> <br> End Sub<br> <br> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load<br> End Sub<br> <br> Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand<br> ' Session("SortInsert") = e.Item.DataItem("image").ToString<br> If validFilesUploaded(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload)) = False Then<br> e.Canceled = True<br> Exit Sub<br> End If<br> Session("ImageInsert") = DirectCast(e.Item.FindControl("txtExistingImage"), TextBox).Text.ToString<br> '<br> InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))<br> <br> <br> End Sub<br> <br> <br> Function validFilesUploaded(ByVal currentUpload As RadUpload) As Boolean<br> If currentUpload.InvalidFiles.Count > 0 Then<br> Me.RadAjaxManager1.Alert("The file you selected is invalid. Please select a JPG file that is under 8 gig in size.")<br> validFilesUploaded = False<br> Else<br> validFilesUploaded = True<br> End If<br> End Function<br> <br> Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload)<br> ' Session("ImageInsert") = ""<br> 'resize and save image<br> ' Set image quality<br> If currentUpload.UploadedFiles.Count > 0 Then<br> <br> <br> <br> Dim intQuality As Integer = System.Configuration.ConfigurationManager.AppSettings("ImageQuality")<br> 'set path<br> currentUpload.TargetFolder = System.Configuration.ConfigurationManager.AppSettings("RootImagePath")<br> <br> <br> <br> Dim abpath As String<br> Dim validFile As UploadedFile<br> <br> 'set time for file name<br> Dim idTime As String = DateTime.Now.ToString("yy_MM_dd") & "_" & DateTime.Now.Hour() & DateTime.Now.Minute() & DateTime.Now.Second<br> abpath = Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension())<br> 'save file as temp file before altering<br> currentUpload.UploadedFiles(0).SaveAs(abpath, True)<br> Dim maxHeight As Int16<br> Dim maxWidth As Int16<br> Dim originalimg, originalimg1, thumb As System.Drawing.Image<br> Dim strFileName, strFileName1 As String<br> Dim width, height, oheight, owidth As Integer<br> Dim width1, height1 As Integer<br> Dim rootpath As String<br> Dim strFilePath As String<br> Dim strFilePath1 As String<br> Dim strFolder As String<br> <br> originalimg = originalimg.FromFile(abpath) ' Fetch User Filename<br> <br> 'get original dimensions so ratio will remain when resizing<br> oheight = originalimg.Height<br> owidth = originalimg.Width<br> Dim iHeight As Int16<br> Dim iWidth As Int16<br> Dim imageType As String<br> <br> 'set max hieght<br> iHeight = System.Configuration.ConfigurationManager.AppSettings("AlbumMaxHeight")<br> iWidth = iHeight * owidth / oheight ' Assign default height.<br> If oheight > System.Configuration.ConfigurationManager.AppSettings("AlbumMaxHeight") Then<br> iWidth = System.Configuration.ConfigurationManager.AppSettings("AlbumMaxWidth")<br> iHeight = iWidth * oheight / owidth<br> End If<br> imageType = System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath")<br> maxHeight = iHeight<br> maxWidth = iWidth<br> <br> <br> originalimg.Dispose()<br> 'This method draws a new blank image first<br> Dim bm As Bitmap = CType(System.Drawing.Image.FromFile(Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension())), Bitmap)<br> Dim resized As New Bitmap(iWidth, iHeight)<br> Dim g As Graphics = Graphics.FromImage(resized)<br> g.DrawImage(bm, New Rectangle(0, 0, resized.Width, resized.Height), 0, 0, bm.Width, bm.Height, GraphicsUnit.Pixel)<br> g.Dispose()<br> 'Get the list of available encoders<br> Dim codecs() As ImageCodecInfo = ImageCodecInfo.GetImageEncoders()<br> 'find the encoder with the image/jpeg mime-type<br> Dim iciInfo As ImageCodecInfo<br> Dim item As ImageCodecInfo<br> For Each item In codecs<br> If (item.MimeType = "image/jpeg") Then iciInfo = item<br> Next<br> Dim ep As EncoderParameters = New EncoderParameters<br> ep.Param(0) = New System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, intQuality)<br> 'strFilePath = Server.MapPath("/images/photogallery/test/" & Me.ListBox1.SelectedItem.Text.ToString & "/clip") & "\" & strFileName ' Root Folder + FileName<br> Try<br> resized.Save(Path.Combine(Server.MapPath(currentUpload.TargetFolder) + imageType, idTime & currentUpload.UploadedFiles(0).GetExtension()), iciInfo, ep)<br> 'set parameter for image name<br> Session("ImageInsert") = idTime & currentUpload.UploadedFiles(0).GetExtension()<br> Me.AccessDataSource1.UpdateCommand = "UPDATE [tbGroups] SET [GroupName] = ?, [GroupDescription] = ?,[ActiveGroup] = ?, [Image] = ? WHERE [Id] = ?"<br> <br> <br> Catch ex As Exception<br> Response.Write(ex.Message)<br> End Try<br> bm.Dispose()<br> resized.Dispose()<br> File.Delete(Path.Combine(Server.MapPath(currentUpload.TargetFolder), currentUpload.UploadedFiles(0).GetNameWithoutExtension() + currentUpload.UploadedFiles(0).GetExtension()))<br> <br> Else<br> 'Me.AccessDataSource1.UpdateParameters(<br> 'Me.RadAjaxManager1.Alert(Session("ImageInsert"))<br> ' Me.AccessDataSource1.UpdateCommand = "UPDATE [tbGroups] SET [GroupName] = @GroupName, [GroupDescription] = @GroupDescription, [ActiveGroup] = @ActiveGroup, [Image] = @original_Image WHERE [Id] = @Id"<br> ' Me.RadAjaxManager1.Alert(Me.AccessDataSource1.UpdateCommand)<br> <br> 'Session("ImageInsert") = Me.AccessDataSource1.UpdateParameters("original_Image")<br> <br> <br> <br> End If<br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> <br> End Sub<br> <br> <br> <br> <br> <br> Function DisplayImage(ByVal sImage As String) As String<br> If File.Exists(Server.MapPath(sImage)) Then<br> DisplayImage = sImage<br> Else<br> DisplayImage = "/images/noimage.gif"<br> End If<br> End Function<br> <br> <br> Function UpdateXML() As String<br> <br> Dim settings As New XmlWriterSettings<br> settings.Indent = True<br> settings.Encoding = Encoding.UTF8<br> settings.ConformanceLevel = ConformanceLevel.Auto<br> settings.Indent = True<br> settings.IndentChars = ControlChars.Tab<br> settings.NewLineHandling = NewLineHandling.Entitize<br> settings.NewLineChars = vbCrLf<br> settings.NewLineHandling = NewLineHandling.Entitize<br> settings.NewLineOnAttributes = True<br> settings.OmitXmlDeclaration = True<br> Dim iCounter As Integer = 1<br> Dim xmlDoc As String = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("ImagesXMLLocation") & "/Images.xml")<br> Dim writer As XmlWriter<br> writer = XmlWriter.Create(xmlDoc, settings)<br> writer.WriteStartDocument()<br> <br> <br> Try<br> Dim connString As String<br> connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & _<br> Server.MapPath("/app_data/imagegallery.mdb")<br> <br> Dim objConnection As OleDbConnection<br> objConnection = New OleDbConnection(connString)<br> objConnection.Open() 'open the connection<br> 'Specify our SQL statement<br> Dim strSQL As String = "SELECT * FROM [tbGroups] WHERE ActiveGroup = True ORDER BY SortId "<br> <br> 'Create the Command object<br> Dim objCommand As OleDbCommand<br> Dim objCommandDetail As OleDbCommand<br> objCommand = New OleDbCommand(strSQL, objConnection)<br> objCommandDetail = New OleDbCommand(strSQL, objConnection)<br> <br> ' Set an OleDbDataReader to the command's results<br> Dim objDataReader As OleDbDataReader<br> objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)<br> ' Set an OleDbDataReader to the command's results<br> Dim objDataReaderDetail As OleDbDataReader<br> <br> 'Dim iCt As Integer = 1<br> writer.WriteStartElement("gallery")<br> While objDataReader.Read()<br> writer.WriteStartElement("album")<br> writer.WriteAttributeString("id", iCounter.ToString)<br> writer.WriteAttributeString("title", objDataReader("groupname").ToString)<br> writer.WriteAttributeString("description", objDataReader("groupdescription").ToString)<br> writer.WriteAttributeString("lgPath", System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("LargeImagePath"))<br> writer.WriteAttributeString("tnPath", System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("ThumbImagePath"))<br> writer.WriteAttributeString("tn", Path.Combine(System.Configuration.ConfigurationManager.AppSettings("RootImagePath") & System.Configuration.ConfigurationManager.AppSettings("AlbumImagePath"), objDataReader("image").ToString))<br> <br> objCommandDetail = New OleDbCommand(strSQL, objConnection)<br> objCommandDetail.CommandText = "SELECT * FROM tbImages WHERE [Group] = " & objDataReader("Id")<br> objDataReaderDetail = objCommandDetail.ExecuteReader(CommandBehavior.CloseConnection)<br> While objDataReaderDetail.Read<br> writer.WriteStartElement("img")<br> writer.WriteAttributeString("src", objDataReaderDetail("image").ToString)<br> writer.WriteAttributeString("title", objDataReaderDetail("title").ToString)<br> writer.WriteAttributeString("caption", objDataReaderDetail("caption").ToString)<br> writer.WriteAttributeString("link", objDataReaderDetail("link").ToString)<br> writer.WriteEndElement()<br> End While<br> 'objDataReaderDetail.Close()<br> <br> writer.WriteEndElement()<br> iCounter += 1<br> End While<br> writer.WriteEndDocument()<br> writer.Close()<br> objDataReader.Close()<br> objConnection.Close()<br> objDataReader = Nothing<br> objConnection = Nothing<br> objCommand = Nothing<br> <br> 'If System.IO.File.Exists(Server.MapPath("/Images.xml")) Then<br> 'System.IO.File.Delete(Server.MapPath("/Images.xml"))<br> 'End If<br>' System.IO.File.Copy(Server.MapPath("/app_data/Images.xml"), Server.MapPath("/Images.xml"))<br> <br> <br> UpdateXML = "Your Gallery has been updated. Most browsers save a website state locally when flash is used. For you to see the changes immediately, please delete your cached data. When using Internet Explorer, Go to Tools/Internet Options, and delete your Browser History/Internet Files."<br> Catch ex As Exception<br> 'writer.WriteEndElement()<br> UpdateXML = "An error has occurred. Detail:" & ex.Message<br> writer.Close()<br> End Try<br> <br> <br> End Function<br> <br> <br> <br>End Class<br><br>0
kyle goodfriend
Top achievements
Rank 2
answered on 14 Jun 2011, 12:52 AM
I have found another page that has the same issue. It appears when the grid is getting refreshed, and the progress window is used, it never releases the progress window. Hope this gives some more info to help identify my issue.
0
Hello kyle,
I went though your code and here are my findings:
- You should use only one ajax control to ajaxify the same page content. So you should remove either the RadAjaxManager or the RadAjaxPanel instead of using them both to ajaxify the grid.
- I cannot find any of the solutions provided in the previously sent help article implemented in your code. Can you try implementing the interface as described there and see if it makes any difference?
Additionally, it is possible that server error is thrown upon your action and as a result the page not to work as expected. Try running the web site in debug mode and see if this is the case.
Best wishes,
Iana
the Telerik team
I went though your code and here are my findings:
- You should use only one ajax control to ajaxify the same page content. So you should remove either the RadAjaxManager or the RadAjaxPanel instead of using them both to ajaxify the grid.
- I cannot find any of the solutions provided in the previously sent help article implemented in your code. Can you try implementing the interface as described there and see if it makes any difference?
Additionally, it is possible that server error is thrown upon your action and as a result the page not to work as expected. Try running the web site in debug mode and see if this is the case.
Best wishes,
Iana
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.