Protected Sub FormView2_ItemInserting(sender As Object, e As FormViewInsertEventArgs)
Handles FormView.ItemInserting
Thanks,
Thanks,
The code looks like this now:
Protected Sub FormView2_ItemInserting(sender As Object, e As FormViewInsertEventArgs) Handles FormView.ItemInserting
Dim FormView2 As FormView = DirectCast(sender, FormView)
Dim fu As FileUpload = DirectCast(FormView2.FindControl("FileUpload1"), FileUpload)
If fu.HasFile = True Then
e.Values("PictureFilename") = fu.FileName
fu.SaveAs("<path to server>" + fu.FileName)
Response.Clear()
Response.Redirect("confirmpage.aspx")
Response.[End]()
End If
End Sub
But on the Handles FormView.ItemInserting I get the error:
'Handles clause requires a WithEvents variable defined in the containing type or one of its base types.' so the page will still not run ?
Further, in order to insert the filename of the picture being uploaded I think I miss some code. I have tried to alter basheerkal's code (show earlier in this thread):
</InsertParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
oniteminserting="FormView1_ItemInserting" AllowPaging="True"
BorderColor="#009900" BorderStyle="Solid">
<InsertItemTemplate>
Select File:
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
<br />
File:
<asp:Label ID="filenameLabel" runat="server" Text='<%# Bind("FileName") %>'/>
This happens when trying to use Handles in a Sub definition for a Control that is nested in a Template.
Instead, take the Handles off the Sub definition, and set the OnItemInserting attribute of the FormView in .aspx. (Or Add to the ItemInserting event in code-behind.)
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
This happens when trying to use Handles in a Sub definition for a Control that is nested in a Template.
Instead, take the Handles off the Sub definition, and set the OnItemInserting attribute of the FormView in .aspx. (Or Add to the ItemInserting event in code-behind.)
Thanks for your reply, unfortunaly I am completely lost......my experience is way to limited to understand this, sorry. If you can provide me with some examples or suggestions to my code, it will be highly apreciated :-)
I could. But I reread the thread, and I think there is another problem.
Instead of "Handles FormView.ItemInserting", use "Handles FormView1.ItemInserting". If your FormView has yet another ID, use that instead of "FormView1".
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
I have tried a 'smaller version' to see if I get get it to work;
I am trying to setup a Formview that includes several operations when data is inserted. Data needs to be inserted, image file must be uploaded, image file name must be inserted in DB as well - and finally user must be redirected to another page.
I can make the data insert work (except for the image file name) and the redirection after data insert works - but I cannot make work together ?
and this is the VB page; it does not include anything about the file upload as I dont know how to (I do have the full path to the folder where pictures shall be uploaded to, and I can make that work alone) ?
Partial Class StaffID_StaffIDdataInsertForm
Inherits System.Web.UI.Page
Protected Sub FormView1_ItemInserted(sender As Object, e As FormViewInsertedEventArgs)
Not sure it is the problem. But Response.Redirect is usually used without the Response.Clear and Response.End calls. The latter two are used in code-behind only when doing downloads.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
ricas
Member
151 Points
339 Posts
Re: Combine data insert and file upload into one page
Apr 26, 2012 02:32 PM|LINK
Any suggestions to how I move on from here ?
Best regards
..... I am new to all this, so please be patient
Qin Dian Tan...
All-Star
113532 Points
12480 Posts
Microsoft
Re: Combine data insert and file upload into one page
Apr 27, 2012 03:06 AM|LINK
Hi,
Addd this after the event:
Protected Sub FormView2_ItemInserting(sender As Object, e As FormViewInsertEventArgs) Handles FormView.ItemInserting
Thanks,
If you have any feedback about my replies, please contactmsdnmg@microsoft.com.
Microsoft One Code Framework
ricas
Member
151 Points
339 Posts
Re: Combine data insert and file upload into one page
Apr 27, 2012 06:12 AM|LINK
Thanks,
The code looks like this now:
Protected Sub FormView2_ItemInserting(sender As Object, e As FormViewInsertEventArgs) Handles FormView.ItemInserting
Dim FormView2 As FormView = DirectCast(sender, FormView)
Dim fu As FileUpload = DirectCast(FormView2.FindControl("FileUpload1"), FileUpload)
If fu.HasFile = True Then
e.Values("PictureFilename") = fu.FileName
fu.SaveAs("<path to server>" + fu.FileName)
Response.Clear()
Response.Redirect("confirmpage.aspx")
Response.[End]()
End If
End Sub
But on the Handles FormView.ItemInserting I get the error:
'Handles clause requires a WithEvents variable defined in the containing type or one of its base types.' so the page will still not run ?
Further, in order to insert the filename of the picture being uploaded I think I miss some code. I have tried to alter basheerkal's code (show earlier in this thread):
</InsertParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
oniteminserting="FormView1_ItemInserting" AllowPaging="True"
BorderColor="#009900" BorderStyle="Solid">
<InsertItemTemplate>
Select File:
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
<br />
File:
<asp:Label ID="filenameLabel" runat="server" Text='<%# Bind("FileName") %>'/>
<br />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
...to fit mine, but no luck so far.
So far it looks like this:
(end of InsertItemTemplate)
<td class="style15">
<br />
<br />
<br />
<br />
<br />
Picture File Upload:</td>
<td class="style16" colspan="3">
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
</tr>
<tr>
<td colspan="4">
<hr />
</td>
</tr>
</table>
<div class="style7">
<asp:Button ID="Button1" runat="server" CommandName="Insert"
Text="Submit Application" />
<asp:Button ID="Button2" runat="server" CommandName="Cancel" Text="Cancel" />
<br />
</div>
</InsertItemTemplate>
...and nothing in the ItemTemplate to bind the file name from the upload control to the DB ?
How do I alter it ?
Best regards,
..... I am new to all this, so please be patient
ricas
Member
151 Points
339 Posts
Re: Combine data insert and file upload into one page
Apr 27, 2012 01:45 PM|LINK
No idea at all ? :-(
Best regards
..... I am new to all this, so please be patient
superguppie
All-Star
48225 Points
8679 Posts
Re: Combine data insert and file upload into one page
May 02, 2012 03:11 PM|LINK
This happens when trying to use Handles in a Sub definition for a Control that is nested in a Template.
Instead, take the Handles off the Sub definition, and set the OnItemInserting attribute of the FormView in .aspx. (Or Add to the ItemInserting event in code-behind.)
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
ricas
Member
151 Points
339 Posts
Re: Combine data insert and file upload into one page
May 03, 2012 08:50 AM|LINK
Thanks for your reply, unfortunaly I am completely lost......my experience is way to limited to understand this, sorry. If you can provide me with some examples or suggestions to my code, it will be highly apreciated :-)
Best regards
..... I am new to all this, so please be patient
superguppie
All-Star
48225 Points
8679 Posts
Re: Combine data insert and file upload into one page
May 10, 2012 02:06 PM|LINK
I could. But I reread the thread, and I think there is another problem.
Instead of "Handles FormView.ItemInserting", use "Handles FormView1.ItemInserting". If your FormView has yet another ID, use that instead of "FormView1".
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
ricas
Member
151 Points
339 Posts
Re: Combine data insert and file upload into one page
May 10, 2012 03:26 PM|LINK
Thanks,
I have tried a 'smaller version' to see if I get get it to work;
I am trying to setup a Formview that includes several operations when data is inserted. Data needs to be inserted, image file must be uploaded, image file name must be inserted in DB as well - and finally user must be redirected to another page.
I can make the data insert work (except for the image file name) and the redirection after data insert works - but I cannot make work together ?
This is the full code for the aspx page:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="StaffIDdataInsertForm.aspx.vb" Inherits="StaffID_StaffIDdataInsertForm" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<p>
<br />
</p>
<form id="form1" runat="server">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="RecordNo"
DataSourceID="SqlDataSource1" DefaultMode="Insert" OnItemInserted="FormView1_ItemInserted" EnableModelValidation="True"
Height="227px">
<EditItemTemplate>
RecordNo:
<asp:Label ID="RecordNoLabel1" runat="server" Text='<%# Eval("RecordNo") %>' />
<br />
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
FamilyName:
<asp:TextBox ID="FamilyNameTextBox" runat="server"
Text='<%# Bind("FamilyName") %>' />
<br />
ImageFileName:
<asp:TextBox ID="ImageFileNameTextBox" runat="server"
Text='<%# Bind("ImageFileName") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
FirstName:
<asp:TextBox ID="FirstNameTextBox" runat="server"
Text='<%# Bind("FirstName") %>' />
<br />
FamilyName:
<asp:TextBox ID="FamilyNameTextBox" runat="server"
Text='<%# Bind("FamilyName") %>' />
<br />
<br />
<br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
RecordNo:
<asp:Label ID="RecordNoLabel" runat="server" Text='<%# Eval("RecordNo") %>' />
<br />
FirstName:
<asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' />
<br />
FamilyName:
<asp:Label ID="FamilyNameLabel" runat="server"
Text='<%# Bind("FamilyName") %>' />
<br />
ImageFileName:
<asp:Label ID="ImageFileNameLabel" runat="server"
Text='<%# Bind("ImageFileName") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<p>
</p>
<p>
<asp:FileUpload
ID="FileUpload1" runat="server"
Enabled='<%# Eval("ImageFileName") %>' />
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:saConnectionString %>"
DeleteCommand="DELETE FROM [StaffID] WHERE [RecordNo] = @RecordNo"
InsertCommand="INSERT INTO [StaffID] ([FirstName], [FamilyName], [ImageFileName]) VALUES (@FirstName, @FamilyName, @ImageFileName)"
SelectCommand="SELECT * FROM [StaffID]"
UpdateCommand="UPDATE [StaffID] SET [FirstName] = @FirstName, [FamilyName] = @FamilyName, [ImageFileName] = @ImageFileName WHERE [RecordNo] = @RecordNo">
<DeleteParameters>
<asp:Parameter Name="RecordNo" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="FamilyName" Type="String" />
<asp:Parameter Name="ImageFileName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="FamilyName" Type="String" />
<asp:Parameter Name="ImageFileName" Type="String" />
<asp:Parameter Name="RecordNo" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</p>
<div>
</div>
</form>
</body>
</html>
and this is the VB page; it does not include anything about the file upload as I dont know how to (I do have the full path to the folder where pictures shall be uploaded to, and I can make that work alone) ?
Partial Class StaffID_StaffIDdataInsertForm
Inherits System.Web.UI.Page
Protected Sub FormView1_ItemInserted(sender As Object, e As FormViewInsertedEventArgs)
Response.Clear()
Response.Redirect("confirmpage.aspx")
Response.[End]()
End Sub
End Class
..... I am new to all this, so please be patient
superguppie
All-Star
48225 Points
8679 Posts
Re: Combine data insert and file upload into one page
May 14, 2012 03:03 PM|LINK
Not sure it is the problem. But Response.Redirect is usually used without the Response.Clear and Response.End calls. The latter two are used in code-behind only when doing downloads.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.