I have a FormView on a page which allows a user to update an entry in the database. The database is defined using a code first approach, several fields are defined as being required. The form view is shown below, the form view works:
<asp:FormView ID="BikeAdd" runat="server"
ItemType="WLL.DAL.Bike"
InsertMethod="BikeAdd_InsertItem"
DefaultMode="Insert"
RenderOuterTable="false"
OnItemInserted="BikeAdd_ItemInserted"
ValidationGroup="BikeForm"
>
<InsertItemTemplate>
<fieldset>
<div>
<asp:DynamicEntity runat="server" Mode="Insert" />
</div>
<br />
<asp:Button ID="ButtonBikeAdd" runat="server" Text="Insert" CommandName="Insert" />
</fieldset>
</InsertItemTemplate>
</asp:FormView>
On the same page I also have a FileUpload control. Which is shown below:
<asp:FileUpload ID="BikeImgUpload" runat="server" />
<asp:Button runat="server" ID="UploadBtn" Text="Upload Image" OnClick="UploadBtn_Click" />
The problem is that, when I attempt to upload a file, by clicking the 'UploadBtn' nothing happens other than the required field validation control being populated; a '*' is displayed beside required fields. The code behind the upload button is shown below:
protected void UploadBtn_Click(object sender, EventArgs e)
{
if (BikeImgUpload.HasFile)
{
try
{
string location = Path.GetFileName(BikeImgUpload.FileName);
BikeImgUpload.SaveAs(Server.MapPath("~/Images/BikeImages") + location);
Status.Visible = true;
}
catch (Exception ex)
{
Status.Text = "Error:" + ex.Message;
Status.Visible = true;
}
}
}
If anyone has any input on the issue that would be great.
Aucun commentaire:
Enregistrer un commentaire