I'm having an unusual problem where a control of type System.Web.UI.WebControls.Dropdownlist is somehow disappearing when I select 'Save' on my form. I've gone through my code a couple of times and I'm not explicitly altering its Visible property.
Control ProductVersion is disappearing when I select 'Save'. In the code this is captured within protected void btnMultifunction_Click(object sender, EventArgs e)
Here's the code ...
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
public partial class TaskEntry : System.Web.UI.Page
{
private const string _DBConnString = "Data Source=JCAMILLERI\\SQLEXPRESS;Initial Catalog=teamwiki;User ID=teamwiki;Password=password;";
private SqlConnection _conAppDB = new SqlConnection(_DBConnString);
private enum multifunctionButtonFunction {Create, Update, NoUpdate}
private int _selectedProduct = 0;
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack) {
_conAppDB.Open();
Product.Items.Clear();
SqlCommand _getProductSQL = new SqlCommand
(@"select [productID_PK], [product] + ' (' + [product_shortname] + ')' as product
from [teamwiki].[dbo].[product_L]
where [in_use] = 1
order by [product] ASC", _conAppDB);
SqlDataReader _ProductNames = _getProductSQL.ExecuteReader();
Product.DataSource = _ProductNames;
Product.DataTextField = "product";
Product.DataValueField = "productID_PK";
Product.DataBind();
_ProductNames.Close();
}
}
catch (Exception ex) {
throw ex; }
finally {
if (_conAppDB.State == ConnectionState.Open)
{ _conAppDB.Close(); }
}
}
protected void btnMultifunction_Click(object sender, EventArgs e)
{
multifunctionButtonFunction ButtonMode = multifunctionButtonFunction.Create;
if (btnMultifunction.Text == "Create new task")
{
Product.Enabled = true;
calIdealDeliveryDate.Enabled = true;
calLatestDeliveryDate.Enabled = true;
txtRequestedBy.Enabled = true;
lstTaskSubCategory.Enabled = true;
txtTaskDescription.Enabled = true;
lstPriority.Enabled = true;
btnMultifunction.Text = "Save";
ButtonMode = multifunctionButtonFunction.Update;
}
else if (btnMultifunction.Text == "Save") {
Product.Enabled = false;
ProductVersion.Visible = true;
ProductVersion.Enabled = false;
calIdealDeliveryDate.Enabled = false;
calLatestDeliveryDate.Enabled = false;
txtRequestedBy.Enabled = false;
lstTaskSubCategory.Enabled = false;
txtTaskDescription.Enabled = false;
lstPriority.Enabled = false;
if (calIdealDeliveryDate.SelectedDate < DateTime.Now && ButtonMode == multifunctionButtonFunction.Update)
{
Response.Write("Dates cannot be in the past");
ButtonMode = multifunctionButtonFunction.NoUpdate;
}
if (calLatestDeliveryDate.SelectedDate < DateTime.Now)
{
Response.Write("Date cannot be in the past");
ButtonMode = multifunctionButtonFunction.NoUpdate;
}
if (ButtonMode != multifunctionButtonFunction.NoUpdate) {
try
{
_conAppDB.Open();
string _createNewTaskQuery = (@"INSERT INTO [teamwiki].[dbo].[task]
([category_FK1]
,[sub_category_FK2]
,[task_description]
,[priority_FK3]
,[status_FK4]
,[start_date]
,[ideal_delivery_date]
,[latest_delivery_date]
,[task_deadline]
,[request_date]
,[requesting_user]
,[assigned_to]
,[managed_by]
,[implementor_notes]
,[attachment]
,[last_update]
,[in_use]
,[productID_FK5]
,[product_release_FK6])
VALUES ( @category,
@sub_category,
@task_description,
@priority,
@status,
NULL,
@ideal_delivery_date,
@latest_delivery_date,
NULL,
GETDATE(),
@requesting_user,
NULL,
NULL,
NULL,
NULL,
GETDATE(),
@in_use,
@product,
@product_release)");
SqlCommand cmdCreateNewTaskQuery = new SqlCommand(_createNewTaskQuery, _conAppDB);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@category", Global.TaskCategory);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@sub_category", lstTaskSubCategory.SelectedValue);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@task_description", txtTaskDescription.Text);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@priority", 1);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@status", 1);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@ideal_delivery_date", calIdealDeliveryDate.SelectedDate);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@latest_delivery_date", calLatestDeliveryDate.SelectedDate);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@requesting_user", txtRequestedBy.Text);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@in_use", 1);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@product", 1);
cmdCreateNewTaskQuery.Parameters.AddWithValue("@product_release", 1);
cmdCreateNewTaskQuery.ExecuteNonQuery();
string getTaskRef = @"SELECT MAX([taskID_PK]) FROM [teamwiki].[dbo].[task];";
SqlCommand getTaskRefSQL = new SqlCommand(getTaskRef, _conAppDB);
object taskRef = getTaskRefSQL.ExecuteScalar();
if (taskRef != DBNull.Value)
{
txtTaskRef.Text = taskRef.ToString();
}
btnMultifunction.Enabled = false;
}
catch (InvalidCastException)
{
}
catch (Exception ex)
{
throw ex;
}
finally {
_conAppDB.Close();
}
}
}
}
protected void lstPriority_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void txtIdealDeliveryDate_TextChanged(object sender, EventArgs e)
{
}
protected void calLatestDeliveryDate_SelectionChanged(object sender, EventArgs e)
{
}
protected void Products_SelectedIndexChanged(object sender, EventArgs e)
{
if (ProductVersion.Visible == false){
ProductVersion.Visible = true;
ProductVersion.Enabled = true;
string _selectedProduct_s = Product.SelectedValue.ToString();
if (int.TryParse(_selectedProduct_s, out _selectedProduct) == false)
{
throw new Exception();
}
try
{
_conAppDB.Open();
ProductVersion.Items.Clear();
SqlCommand _getProductVersionSQL = new SqlCommand
(@"select product_releaseID_PK, version
from [teamwiki].[dbo].[product_release]
where [in_use] = 1
and productID_FK2 = @productID;", _conAppDB);
_getProductVersionSQL.Parameters.AddWithValue("@productID", _selectedProduct);
SqlDataReader _ProductVersion = _getProductVersionSQL.ExecuteReader();
ProductVersion.DataSource = _ProductVersion;
ProductVersion.DataTextField = "version";
ProductVersion.DataValueField = "product_releaseID_PK";
ProductVersion.DataBind();
_ProductVersion.Close();
}
catch (Exception ex) {
throw ex;
}
finally {
_conAppDB.Close();
}
}
}
protected void ProductVersion_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Jon
|