Пользователь вводит номер клиента, затем выбирает файл для загрузки, затем вводит описание и нажимает кнопку сохранения. Однако, когда я проверяю, выбрали ли они файл, он всегда возвращает false! Я хотел бы знать, почему.
Редактировать: я сейчас использую форму с параметром enctype = "multipart / form-data", и это обернуто в панель обновления Форма и панель обновлений находятся на главной странице
Вот фрагмент кода, который обрабатывает ошибку и получает значение HasFile ():
else if ( ( images.Selected == true || docs.Selected == true ) &&
( Upload.HasFile == false || txtInfo.Text == string.Empty ) )
{
if ( Upload.HasFile == false )
lblErrorMessage.Text = "You haven't selected a file";
else lblErrorMessage.Text = "You must enter a description";
validated = false;
}
И вот метод, который пришел, кнопка сохранения
protected void btnSaveNew_Click( object sender, EventArgs e )
{
bool validated = true;
lblErrorMessage.ForeColor = System.Drawing.Color.Red;
if ( txtCustomerNumber.Text.Length != 8 )
{
if ( txtCustomerNumber.Text.Length == 0 )
lblErrorMessage.Text = "Hey! What about the customer number?";
else if ( txtCustomerNumber.Text.Length > 8 )
lblErrorMessage.Text = "Invalid Customer Number length (" + ( txtCustomerNumber.Text.Length - 8 ) + " char(s) too long)";
else lblErrorMessage.Text = "Invalid Customer Number length (" + ( 8 - txtCustomerNumber.Text.Length ) + " char(s) short)";
validated = false;
}
else if ( links.Selected == true && ( txtLink.Text == string.Empty || txtInfo.Text == string.Empty ) )
{
if ( txtLink.Text == string.Empty )
lblErrorMessage.Text = "Hey! You forgot to enter a link!";
else lblErrorMessage.Text = "You must enter a description";
validated = false;
}
else if ( ( images.Selected == true || docs.Selected == true ) &&
( Upload.HasFile == false || txtInfo.Text == string.Empty ) )
{
if ( Upload.HasFile == false )
lblErrorMessage.Text = "You haven't selected a file";
else lblErrorMessage.Text = "You must enter a description";
validated = false;
}
else if ( txtInfoDesc.Text == string.Empty || txtInfo.Text == string.Empty )
{
if ( txtInfoDesc.Text == string.Empty )
lblErrorMessage.Text = "You must enter an info description";
else lblErrorMessage.Text = "You must enter info Data";
validated = false;
}
if ( validated == false )
{
btnModify.Visible = false;
btnCreateNew.Visible = false;
ddlCustomerNumber.Visible = false;
btnSaveNew.Visible = true;
btnCancel.Visible = true;
txtCustomerNumber.Visible = true;
switch ( rblSection.SelectedIndex )
{
case 0: txtInfo.Visible = true;
txtLink.Visible = true;
break;
case 1:
case 2: txtInfo.Visible = true;
Upload.Visible = true;
break;
case 3: txtInfo.Visible = true;
txtInfoDesc.Visible = true;
break;
}
if ( GetCategoryIDCookie() != 0 )
divData.Attributes.Add( "Style", "overflow:auto" );
}
else
{
addNewCustomerNumber( txtCustomerNumber.Text, txtInfoDesc.Text, txtInfo.Text );
ddlCustomerNumber.Visible = true;
divData.Attributes.Remove( "Style" );
Response.Redirect( Request.RawUrl );
}
}