hi
i have modified the code to resize the image and now how do i pass the newly resize image as byte? Thanks
Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload)
Dim stdWidth As Integer
Dim stdHeight As Integer
If currentUpload.UploadedFiles.Count > 0 Then
Dim img As Bitmap = New Bitmap(currentUpload.UploadedFiles(0).InputStream)
If img.Width > img.Height Then
stdWidth = 500
stdHeight = img.Height / (img.Width / stdWidth)
Else
stdHeight = 500
stdWidth = img.Width / (img.Height / stdHeight)
End If
'I am stuck here
'How to pass the newly resize image here as byte
Dim data As Byte() = New Byte(currentUpload.UploadedFiles(0).ContentLength) {}
currentUpload.UploadedFiles(0).InputStream.Read(data, 0, data.Length)
Session(
"DataVB") = data
End If
End Sub
6 Answers, 1 is accepted

I have solved the Resize Image thing. I have already tested it on the RadUploadInAjaxifiedGrid demo Application and is working fine. Remember that the RadUploadInAjaxifiedGrid demo uses RadAjaxPanel1.ResponseScripts and not RadAjaxManagerProxy. And it is not using Stored Proc for insert.
But now, i have this Operand type clash: nvarchar is incompatible with image.
In this case my actual page is using RadAjaxManagerProxy and Stored Proc for insert. Ok here are my table, SP, ASPX and Code behind.
Table:
[ID] [int]
IDENTITY(1,1) NOT NULL,
[SellerName] [nvarchar]
(100) NULL,
[TransType] [nvarchar]
(10) NULL,
[SellPrice] [nvarchar]
(15) NULL,
[Address] [nvarchar]
(200) NULL,
[Type] [nvarchar]
(50) NULL,
[Location] [nvarchar]
(200) NULL,
[Image] [image]
NULL,
[AddInfo] [nvarchar]
(max) NULL,
[AddDate] [date]
NULL,
[ExpDate] [date]
NULL,
[Username] [nvarchar]
(50) NULL,
[UserType] [nvarchar]
(50) NULL,
Stored Proc:
Create Proc [dbo].[spSell_AddNew]
@SellerName as Nvarchar(100),
@SellPrice as Nvarchar(15),
@Address as Nvarchar(200),
@Type as Nvarchar(50),
@Location as Nvarchar(200),
@Image as Image,
@AddInfo as Nvarchar(Max),
@Username as Nvarchar(50),
@UserType as Nvarchar(50)
as
INSERT INTO [tblSell]
([SellerName]
,[SellPrice]
,[Address]
,[Type]
,[Location]
,[Image]
,[AddInfo]
,[Username]
,[UserType])
VALUES
(@SellerName, @SellPrice,@Address,@Type,@Location,@Image,@AddInfo,@Username,@UserType)
ASPX
<%@ Page Title="" Language="VB" MasterPageFile="~/master/main.master" AutoEventWireup="false" CodeFile="hdbsell.aspx.vb" Inherits="Agent_Customer_hdbbs" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<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>
<style type="text/css">
.style1
{
width: 100%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder3" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table cellpadding="0" cellspacing="0" class="style1">
<tr>
<td>
<telerik:RadMenu ID="RadMenu1" Runat="server"
DataSourceID="sdsmenuLocation" DataTextField="Location" Skin="Sunset"
Width="100%" DataValueField="Location">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</telerik:RadMenu>
<asp:SqlDataSource ID="sdsmenuLocation" runat="server"
ConnectionString="<%$ ConnectionStrings:ertyConnString %>"
SelectCommand="spMenuLocation" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
DataSourceID="sdsProd" GridLines="None" Skin="Gray" Width="100%"
AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" AllowPaging="True" AllowSorting="True">
<HeaderContextMenu>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView DataSourceID="sdsProd" CommandItemDisplay="Top" DataKeyNames="ID">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn DataField="SellerName"
HeaderText="Owner's Name" SortExpression="SellerName"
UniqueName="SellerName">
<EditItemTemplate>
<asp:TextBox ID="SellerNameTextBox" runat="server"
Text='<%# Bind("SellerName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="SellerNameLabel" runat="server"
Text='<%# Eval("SellerName") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Address" HeaderText="Address"
SortExpression="Address" UniqueName="Address">
<EditItemTemplate>
<asp:TextBox ID="AddressTextBox" runat="server"
Text='<%# Bind("Address") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="AddressLabel" runat="server"
Text='<%# Eval("Address") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Type" HeaderText="Type"
SortExpression="Type" UniqueName="Type">
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox2" Runat="server"
DataSourceID="sdsType" DataTextField="Type" DataValueField="Type" SelectedValue='<%# Bind("Type") %>' Skin="Gray">
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="RoomLabel" runat="server" Text='<%# Eval("Type") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Location" HeaderText="Location"
SortExpression="Location" UniqueName="Location">
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox1" Runat="server" AppendDataBoundItems="true"
DataSourceID="sdsDrpLocation" selectedValue='<%# Bind("Location") %>' ZIndex="10000" DataValueField="Location" DataTextField="Location" Skin="Gray">
<CollapseAnimation Duration="200" Type="OutQuint" />
</telerik:RadComboBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="LocationLabel" runat="server"
Text='<%# Eval("Location") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Picture" UniqueName="Image">
<EditItemTemplate>
<telerik:RadUpload ID="RadUpload1" runat="server" InitialFileInputsCount="1" MaxFileInputsCount="1"
ControlObjectsVisibility="None" MaxFileSize="1000000" AllowedFileExtensions=".jpg,.bmp,.gif,.dib,.jpeg,.jpe,.jfif,.png,.tif,.tiff" />
</EditItemTemplate>
<ItemTemplate>
<<a href="ShowImageVB.aspx?id=<%# Eval("ID") %>">
<asp:Image runat="server" ID="ImageThumbnail" AlternateText="Click here to open the real size image"
ImageUrl='<%# "ShowImageVB.aspx?thumbnail=true&ID=" & Eval("ID")%>' Style="border-width: 0px;" />
</a>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="SellPrice" DataType="System.String"
HeaderText="Sell Price" SortExpression="SellPrice"
UniqueName="SellPrice">
<EditItemTemplate>
<asp:TextBox ID="SellPriceTextBox" runat="server"
Text='<%# Bind("SellPrice") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="SellPriceLabel" runat="server"
Text='<%# Eval("SellPrice") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="AddInfo" DataType="System.String"
HeaderText="Addition Info" SortExpression="AddInfo"
UniqueName="AddInfo">
<EditItemTemplate>
<asp:TextBox ID="AddInfoTextBox" TextMode="MultiLine" Width="250px" Height="50px" runat="server"
Text='<%# Bind("AddInfo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="AddInfoLabel" runat="server"
Text='<%# Eval("AddInfo") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="AddDate" DataType="System.DateTime"
HeaderText="Date Added" SortExpression="AddDate" UniqueName="AddDate">
<ItemTemplate>
<asp:Label ID="AddDateLabel" runat="server"
Text='<%# Eval("AddDate") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn Display="false" DataField="Username" DataType="System.String"
SortExpression="Username" UniqueName="Username">
<EditItemTemplate>
<asp:TextBox ID="UsernameTextBox" runat="server"
Visible="False" Text='<%# Bind("Username") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="UsernameLabel" runat="server"
Text='<%# Eval("Username") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit">
<HeaderStyle Font-Size="11px" />
</telerik:GridEditCommandColumn>
<telerik:GridButtonColumn CommandName="Delete" ConfirmText="Are you sure?"
ConfirmTitle="Confirmation" Text="Delete" UniqueName="column1"
HeaderText="Delete">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
<PagerStyle Mode="NumericPages" />
</MasterTableView>
<FilterMenu>
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
<asp:SqlDataSource ID="sdsType" runat="server"
ConnectionString="<%$ ConnectionStrings:ertyConnString %>"
SelectCommand="spType" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsDrpLocation" runat="server"
ConnectionString="<%$ ConnectionStrings:ertyConnString %>"
SelectCommand="spLocation" SelectCommandType="StoredProcedure">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdsProd" runat="server"
ConnectionString="<%$ ConnectionStrings:ertyConnString %>"
DeleteCommand="spSell_Delete" DeleteCommandType="StoredProcedure"
SelectCommand="spSell_Select" SelectCommandType="StoredProcedure"
InsertCommand="spSell_AddNew" InsertCommandType="StoredProcedure"
UpdateCommand="spSell_Update" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="choice" DefaultValue="Alpha" SessionField="choice" Type="String" />
<asp:SessionParameter DefaultValue="A" Name="alpha" SessionField="value"
Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="SellerName" Type="String" />
<asp:Parameter Name="SellPrice" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Location" Type="String" />
<asp:SessionParameter SessionField="DataVB" Name="Image"/>
<asp:Parameter Name="AddInfo" Type="String" />
<asp:Parameter Name="Username" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="SellerName" Type="String" />
<asp:Parameter Name="SellPrice" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Location" Type="String" />
<asp:SessionParameter SessionField="DataVB" Name="Image"/>
<asp:Parameter Name="AddInfo" Type="String" />
<asp:Parameter Name="Username" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadMenu1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManagerProxy>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</asp:Content>
Code Behind:
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports System.IO
Imports Telerik.Web.UI
Imports System.Drawing
Imports System.Drawing.Imaging
Partial Class Agent_Customer_hdbbs
Inherits System.Web.UI.Page
Dim x As New DAL
Protected Sub RadMenu1_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadMenuEventArgs) Handles RadMenu1.ItemClick
Select Case e.Item.Text
Case "All"
Session("value") = e.Item.Text
Session("choice") = "All"
Case Else
Session("value") = e.Item.Text
Session("choice") = "Alpha"
End Select
End Sub
Protected Sub radGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound
Session("Username") = "naiwah"
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
If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then
Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
Dim Username As TextBox = DirectCast(insertItem("Username").FindControl("UsernameTextBox"), TextBox)
Username.Text = Session("Username")
End If
End Sub
Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))
End Sub
Protected Sub RadGrid1_InsertCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)
InitializeUpdateParameter(DirectCast(e.Item.FindControl("RadUpload1"), RadUpload))
End Sub
Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload)
Dim stdWidth As Integer
Dim stdHeight As Integer
Dim imgStream As New MemoryStream
Dim img As Bitmap = New Bitmap(currentUpload.UploadedFiles(0).InputStream)
If currentUpload.UploadedFiles.Count > 0 Then
If img.Width > img.Height Then
stdWidth = 500
stdHeight = img.Height / (img.Width / stdWidth)
Else
stdHeight = 500
stdWidth = img.Width / (img.Height / stdHeight)
End If
Dim NewSize As System.Drawing.Size = New System.Drawing.Size(stdWidth, stdHeight)
Dim newimg As New Bitmap(img, NewSize.Width, NewSize.Height)
newimg.Save(imgStream, ImageFormat.Jpeg)
Dim data As Byte() = imgStream.ToArray()
imgStream.Read(data, 0, data.Length)
Session("DataVB") = data
End If
End Sub
End Class
As you can see, the InitializeUpdateParameter is almost the same as RadUploadInAjaxifiedGrid demo but it has been modified for reszing of image.
Please help and if you could expediate it i would greatly appreciate it. Thanks

Ok, I know what is the cause of the problem. It is the ProxyManager. I have replace it with RadAjaxPanel and is inserting fine.
But there is another problem. The update failed. I have used your raduploadinajaxifiedgrid demo and have change the sessionDatasource to SQLDataSource for update testing, It failed. This is the code:
Private Sub InitializeUpdateParameter(ByVal currentUpload As RadUpload)
Dim stdWidth As Integer
Dim stdHeight As Integer
Dim imgStream As New MemoryStream
Dim img As Bitmap = New Bitmap(currentUpload.UploadedFiles(0).InputStream)
If currentUpload.UploadedFiles.Count > 0 Then
If img.Width > img.Height Then
stdWidth = 500
stdHeight = img.Height / (img.Width / stdWidth)
Else
stdHeight = 500
stdWidth = img.Width / (img.Height / stdHeight)
End If
Dim NewSize As System.Drawing.Size = New System.Drawing.Size(stdWidth, stdHeight)
Dim newimg As New Bitmap(img, NewSize.Width, NewSize.Height)
newimg.Save(imgStream, ImageFormat.Jpeg)
Dim data As Byte() = imgStream.ToArray()
imgStream.Read(data, 0, data.Length)
Session(
"DataVB") = data
End If
Also, in your online demo, whenever i refresh the page using the browser button not the grid refresh button. It keeps on inserting everytime i refreshes the page. How do i solve this also? Thanks.

Sorry, something to addon here. On your online demo RadUploadInAjaxifiedGrid, after inserting a picture and then refresh the page using the browswer refresh button. Not the grid one. You should see that the grid will insert itself a picture automatically.
And why is it so slow for a reply?
Thank you for your questions.
- By default, when you use SQLDataSource, on Update, all fields of the object to insert are being compared for equality with the object in the database. This means that your newly inserted image is being compared with the already inserted one, which is not supported. To get around the problem you need to compare only by ID, not by all fields. What you need to do is to modify the Update command. It should compare only by primary key. Example:
UpdateCommand="UPDATE ........ WHERE [PrimakyKey] = @original_PrimaryKey">
As you can see, in the where clause only the IDs are compared.
For your convenience I have represented sample project describing your problem. You can find it as an attachment.
- Since uploads are done with full post-back to the server, pressing F5 will re-submit the form. You will get notification for this in IE for example. i.e When you press F5, the form is submitted once again with the previous information. Unfortunately, I am not aware of solution to this issue.
Let me know whether the proposed solution helps.
Regards,
Genady Sergeev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

I did all i could to follow your attached example but it still it is not updating and now cannot delete. it always say "Index Out of range. Must be Non-negative and less than the size of collection.
Here is my updateed ASPX code. It is based on your online demo. No changes to Code Behind. Please help! Thanks
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:TelerikConnectionString %>"
SelectCommand="SELECT * FROM [Images]"
InsertCommand="INSERT INTO [Images] ([Name], [Description], [Data]) VALUES (@Name, @Description, @Data)"
UpdateCommand="UPDATE [Images] SET [Name] = @Name, [Description] = @Description, [Data] = @Data WHERE [ID] = @original_ID"
DeleteCommand="DELETE FROM [Images] WHERE [ID] = @original_ID and (([Name] = @original_Name) or ([Description] = @original_Description OR ([Description] IS NULL AND @original_Description IS NULL)) AND (([Data] = @original_Data) OR ([Data] IS NULL AND @original_Data IS NULL))"
OldValuesParameterFormatString="original_{0}">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:SessionParameter SessionField="DataVB" Name="Data" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:SessionParameter SessionField="DataVB" DbType="Object" Name="Data" />
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Data" Type="Object" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="original_Name" Type="String" />
<asp:Parameter Name="original_Description" Type="String" />
<asp:Parameter Name="original_Data" Type="Object" />
</DeleteParameters>
</asp:SqlDataSource>
I have fixed your code, you can find it as an attachment. The problem seemed to be in the ConflictResolution property and in the DeleteCommand parameters. ConflictResolutin should be set to OverwriteChanges. Delete as well as Update should be done by primary key, no additional fields should be compared.
In concern to the update issue I have to admit that there is a bug in the online demo. The case is that the session field that holds the image is not being reset after insert and update. We are sorry for the inconvenience. To compensate I have attached correct sample demo describing your issue, with Delete, Update and Insert properly working. Please notice the session reset in methods: RadGrid_InsertCommand and RadGrid_UpdateCommand. I have attached my test database as well.
Please let me know whether the proposed solution helps.
All the best,
Genady Sergeev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.