Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checkbox assign 1

Status
Not open for further replies.

kurie

Programmer
Jun 4, 2008
170
ZA
Hie guys
Isn't this legal
this.chkActive.Checked = Convert.ToBoolean(dtr["Active"]);
chkActive is a checkbox
error message on built application is: form does not contain a definition for 'chkActive'

but chkActive is control i have verified its presence on the form. I just dont understand

<hate Computers>
 
Hi
jmeckley- how did u solve this, would u know whats causing it. i have used a checked box before and it worked fine.

<hate Computers>
 
delete the control and added again. that's the simplest resolution.
why is this happening? could be the design file or form file was corrupted, or something else entirely. Do you have any code which would remove the checkbox from the form?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hi all
@jmeckley: i have deleted and added a new one with a new name and it didnt work.
It works fine on some forms but doesnt work on others. No, i dont have code that is removing any control, if i do type "this. <ctr space>" it sees the control but on debuging its not seen, so its not code that is removing it.(cant remove by debugging).
 
i'm at a loss. could you post the code?

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hie, this is part of the code
this.tboLastname.Text = "" +(string)dtr["LastName"];
this.tboMobile.Text = "" + (string)dtr["Mobile"];
this.tboPostcode.Text = "" + (string)dtr["PostCode"];
this.tboTele.Text = "" + (string)dtr["Telephone"];
this.tboUsername.Text = "" + (string)dtr["Username"];
this.CheckBox1.Checked = (bool)dtr["checked"]; // contol in question

May be i have to reintall my framework.
 
i meant the cs file. code like events, functions, fields, properties. the code above doesn't give any insight into how it relates to the screen.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
good day,
Here is the whole code from the page, I hope its clear on your page.

public partial class EditUsers : System.Web.UI.Page
{
int intUserID = 0;
string strUserName = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["name"] != null)
{
strUserName = "" + Session["name"].ToString();
//string strUserName = "";
}
else
{
strUserName = "";
}
if (!IsPostBack)
{
loadListbox();
}
}
private void loadListbox()
{
try
{
lboUsers.Items.Clear(); // .Items.Clear();
//string sql = "SELECT CompanyName from Company";

con.Open();
// String con = "Data Source=Webserver\\Webserver;Initial Catalog=IntelligentThinkingKeyGenerator;User ID=sa;Password=PH-Factor;";

//SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
//ConfigurationManager.ConnectionStrings["con"].ConnectionString);
//DataSet customers = new DataSet();
//'adapter.Fill(customers, "Customers");
SqlCommand com = new SqlCommand("sproc_UserSelectAll", con);
com.CommandType = CommandType.StoredProcedure;
SqlDataReader dtr = com.ExecuteReader();
while (dtr.Read())
{
string name = (string)dtr["Username"];
int coid = (int)dtr["UserID"];
ListItem item = new ListItem(name);
item.Value = Convert.ToString(coid);
item.Text = name;
lboUsers.Items.Add(item);
lboUsers.DataBind();
//cboCompanyName.Items.Add("name");
//cboCompanyName.app
}
con.Close();
dtr.Close();
}
catch (Exception ex)
{
}


}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
// Create the DataSet object

conn.Open();

//conn.Open();
SqlCommand cmdInsert = new SqlCommand("sproc_UserUpdate", conn);
cmdInsert.CommandType = CommandType.StoredProcedure;
//cmdInsert.Parameters.Add(new SqlParameter("@OrderId", SqlDbType.Int));
//cmdInsert.Parameters["@OrderId"].Direction = ParameterDirection.Output;
//cmdInsert.Parameters["@OrderId"].SourceColumn = "OrderId";
intUserID = Convert.ToInt32(lboUsers.SelectedItem.Value);
cmdInsert.Parameters.AddWithValue("@UserID", intUserID);
cmdInsert.Parameters.AddWithValue("@Username", tboUsername.Text);
cmdInsert.Parameters.AddWithValue("@Password", tboPassword.Text);
cmdInsert.Parameters.AddWithValue("@Firstname", tboFirstname1.Text);
cmdInsert.Parameters.AddWithValue("@Lastname", tboLastname.Text);
cmdInsert.Parameters.AddWithValue("@Address1", tboAddress1.Text);
cmdInsert.Parameters.AddWithValue("@Address2", tboAddress2.Text);
cmdInsert.Parameters.AddWithValue("@Address3", tboAddress3.Text);
cmdInsert.Parameters.AddWithValue("@Address4", "");
cmdInsert.Parameters.AddWithValue("@Postcode", tboPostcode.Text);
cmdInsert.Parameters.AddWithValue("@Telephone", tboTele.Text);
cmdInsert.Parameters.AddWithValue("@Mobile", tboMobile.Text);
cmdInsert.Parameters.AddWithValue("@Fax", tboFax.Text);
cmdInsert.Parameters.AddWithValue("@Email", tboEmail.Text);
// cmdInsert.Parameters.AddWithValue("@Isadmin",true);
cmdInsert.Parameters.AddWithValue("@DateLastUpdated", DateTime.Now);
cmdInsert.Parameters.AddWithValue("@Updatedby", strUserName);
cmdInsert.Parameters.AddWithValue("@Active", true);
cmdInsert.ExecuteNonQuery();
// Label5. = true;
lblInfo.Text = "User Updated Succesfully";
cmdInsert.Dispose();
conn.Close();
}

catch(Exception ex)
{
}

}
protected void btnClose_Click(object sender, EventArgs e)
{
this.tboAddress1.Text = "";
this.tboAddress2.Text = "";
this.tboAddress3.Text = "";
this.tboEmail.Text = "";
this.tboFax.Text = "";
this.tboFirstname1.Text = "";
this.tboLastname.Text = "";
this.tboMobile.Text = "";
this.tboPassword.Text = "";
this.tboPostcode.Text = "";
this.tboTele.Text = "";
this.tboUsername.Text = "";
}
protected void lboUsers_SelectedIndexChanged(object sender, EventArgs e)
{

intUserID = Convert.ToInt32(lboUsers.SelectedItem.Value);
try
{
this.tboAddress1.Text = "";
this.tboAddress2.Text = "";
this.tboAddress3.Text = "";
this.tboEmail.Text = "";
this.tboFax.Text = "";
this.tboFirstname1.Text = "";
this.tboLastname.Text = "";
this.tboMobile.Text = "";
this.tboPassword.Text = "";
this.tboPostcode.Text = "";
this.tboTele.Text = "";
this.tboUsername.Text = "";
lblInfo.Text = "";
//this.tboUsername.Text = Convert.ToString(chkActive.Checked);
if (intUserID != 0)
{


con.Open();
SqlCommand com = new SqlCommand("sproc_UserSelectForListbox", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.AddWithValue("@UserID", intUserID);
SqlDataReader dtr = com.ExecuteReader();
while (dtr.Read())
{ this.tboUsername.Text = "" + (string)dtr["Username"];
this.tboAddress1.Text = "" + (string)dtr["Address1"];
this.tboAddress2.Text = "" + (string)dtr["Address2"];
this.tboAddress3.Text = "" + (string)dtr["Address3"];
this.tboEmail.Text = "" + (string)dtr["email"];
this.tboFax.Text = "" + (string)dtr["fax"];
this.tboFirstname1.Text = "" + (string)dtr["Firstname"];
this.tboLastname.Text = "" +(string)dtr["LastName"];
this.tboMobile.Text = "" + (string)dtr["Mobile"];
this.tboPassword.Text = "" + (string)dtr["Password"];
this.tboPostcode.Text = "" + (string)dtr["PostCode"];
this.tboTele.Text = "" + (string)dtr["Telephone"];
this.tboUsername.Text = "" + (string)dtr["Username"];
//this.CheckBox1.Checked = (bool)dtr["checked"];

}
con.Close();
//if (tboLicence1.Text == "")
//{
// lblInformation1.Text = "No Key for Company";
//}
dtr.Dispose();
con.Close();
com.Dispose();
}
}
catch (Exception ex)
{
//
}

}
protected void chkActive1_CheckedChanged(object sender, EventArgs e)
{

}
}
 
your first problem is your catching the exceptions without doing anything with them. remove the try/catch blocks from the page. then test. I'm sure the problem is an exception was thrown and then swallowed. Research some of the guide lines for managing exceptions. this will help you better manage your systems health.

Your on the right path with your connection/command objects by closing/disposing. however your current setup won't properly dispose/close if an exception is thrown.

1 of 2 methods is recommended
Code:
DatTable results = new DataTable();
using(IDbConnection cnn = new SqlConnection())
using(IDbCommand cmd = cnn.CreateCommand())
{
   cnn.Open();
   cmd.CommandText = "select ...";
   results.Load(cmd.ExecuteReader());
   //no need to explicitly close/dispose here, the using statement is syntax sugar to automatically do that
}
return results;
or
Code:
DataTable results = new DataTable();
IDbConnection cnn = new SqlConnection();
IDbCommand cmd = null;
try
{
   cnn.Open();
   cmd.CreateCommand();
   cmd.CommandText = "select ...";
   results.Load(cmd.ExecuteReader());
}
finally
{
   if(cnn.ConnectionState != ConnectionState.Closed)
      cnn.Close();
   cnn.Dispose();
   if(cmd != null)
      cmd.Dispose();
}
return results;
since your adding items to the list control you don't need to databind.
either use the datasource/bind method or the items.add method. not both.

I would recommend letting the webform do what it does best and use
ListControl.DataSource = results;
ListControl.DataBind();
over ListControl.Items.Add().

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
while non of my previous post has anything to do with the check box problem. simply removing the try/catch should expose the problem.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hie
@jmeckley, thanks very much. But the checkbox dont give error message at runtime so when i removed the "try catch" the same error message appered, Anywhere thanks very much for your help, i will have to use something else on those pages.
 
Can you post the stacktrace & exact error message?

Chip H.


____________________________________________________________________
www.chipholland.com
 
The name 'chkActive' does not exist in the current context C:\Projects\Version9\WebClientNew\Web Cleint\Home Page\frmSite.aspx.cs 59 9 C:\...\Web Cleint\

chkActive is the checkbox i have created.
Can i do a trace on debug, coz the error message is on debug not at run time.
 
I've had a similar problem just recently, and it seemed that my VS2005 was messing up a bit. When I changed the name property of a component, it did not change the variable name inside the autogenerated code, and when I tried to reference it by its name, I had the same error you are getting.

You might want to try and check the auto-generated code where the components are declared and see that the variable name is correct (maybe inside frmSite.Designer.aspx.cs? I'm not sure if it works the same as in windows applications)

|| ABC
 
hi all
@abcfantasy: thank you very much i tried changing that but it still didnt work. maybe i need a new service pack, right now im on sp1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top