Hi i have a formview from where the user is able to update data, one of my database fields is picture. From Edit Edit Templates i have added file upload control and label and button. What i want is when i press the button the file to be saved into folder
and the path string to be assigned to the picturetextbox.
The problem is when i write the script, it says that the controls are not declared despite that they exist in the Form View control.
It seems that this is kind of problem with the hierarchy of the controls.
Here is my code.... Hope somebody will tell me how to resolve this issue.:
<
script
language=VBSCRIPT
runat=server>
Protected Sub UploadButton_Click(ByVal
sender As Object,
ByVal e
As EventArgs) Handles btnSubmit.click
If UploadFile.HasFile =
False
Then
' No file uploaded!
lblPath.Text =
"Please first select a file to upload..."
Else
' Display the uploaded file's details
lblPath.Text = String.Format( _
"Uploaded file: {0}<br />" & _
"File size (in bytes): {1:N0}<br />" & _"Content-type: {2}",
_
Orchida
Member
1 Points
12 Posts
FormView, custom controls problems with the script
May 07, 2008 06:39 PM|LINK
Hi i have a formview from where the user is able to update data, one of my database fields is picture. From Edit Edit Templates i have added file upload control and label and button. What i want is when i press the button the file to be saved into folder and the path string to be assigned to the picturetextbox.
The problem is when i write the script, it says that the controls are not declared despite that they exist in the Form View control.
It seems that this is kind of problem with the hierarchy of the controls.
Here is my code.... Hope somebody will tell me how to resolve this issue.:
<
script language=VBSCRIPT runat=server> Protected Sub UploadButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.click
If UploadFile.HasFile = False Then ' No file uploaded!lblPath.Text =
"Please first select a file to upload..." Else ' Display the uploaded file's details lblPath.Text = String.Format( _ "Uploaded file: {0}<br />" & _ "File size (in bytes): {1:N0}<br />" & _"Content-type: {2}", _UploadFile.FileName, _
UploadFile.FileBytes.Length, _
UploadFile.PostedFile.ContentType)
lblPath.Text = String.Format("http://blabla/BMP/" & UploadFile.FileName)PictureTextBox.Text = lblPath.text
' Save the file Dim filePath As String = _Server.MapPath("~/BMP/" & UploadFile.FileName)UploadFile.SaveAs(filePath)
End If End Sub
</script>----------------------------------------------------------------------
<EditItemTemplate>PTName:
<asp:Label ID="PTNameLabel1" runat="server" Text='<%# Eval("PTName") %>'></asp:Label><br />Picture:
<asp:TextBox ID="PictureTextBox" runat="server" Text='<%# Bind("Picture") %>'> </asp:TextBox> <asp:Label ID="lblPath" runat="server" Text="Label"></asp:Label> <asp:FileUpload ID="UploadFile" runat="server" /> <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="UploadButton_Click" /><br />Profile:
<asp:TextBox ID="ProfileTextBox" runat="server" Text='<%# Bind("Profile") %>'> </asp:TextBox><br />Philosophy:
<asp:TextBox ID="PhilosophyTextBox" runat="server" Text='<%# Bind("Philosophy") %>'> </asp:TextBox><br />KeyPoints:
<asp:TextBox ID="KeyPointsTextBox" runat="server" Text='<%# Bind("KeyPoints") %>'> </asp:TextBox><br />Testimonials:
<asp:TextBox ID="TestimonialsTextBox" runat="server" Text='<%# Bind("Testimonials") %>'> </asp:TextBox><br /> <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update"> </asp:LinkButton> <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"> </asp:LinkButton> </EditItemTemplate>