Hi,
One problem is that your page load event fires twice because you have AutoEventWireup="true" and you have
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new EventHandler(Page_Load);
}
so the event is wired twice and will fire twice.
It isn't really clear to me why you are using 2 UpdatePanels, I would use just one with UpdateMode="Conditional"
I think the call from PageLoad to PopulateControls should not be in the try catch and probably should be wrapped in
if(!Page.IsPostback)
because if you are using viewstate it should not need to rebind those dropdowns on postback
also you should not have any of this in a UserControl:
<link href="GPI.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.style1
{
width: 309px;
}
</style>
it is invalid html to have that outside of head and it won't correctly resolve the url for GPI.css
Also if any error happens in your code the connection remains open, assuming you are using the same connection string as mojoPortal, you can simplify and improve this code:
SqlConnection conn = new SqlConnection(GetConnectionString());
conn.Open();
SqlCommand sqlcommand = new SqlCommand("select Name from propertytype");
sqlcommand.Connection = conn;
SqlDataReader dr = sqlcommand.ExecuteReader();
//SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlcommand);
ddPropertyType.Items.Clear();
ListItem li = new ListItem();
li.Text = "Any";
li.Value = "Any";
ddPropertyType.Items.Add(li);
while (dr.Read())
{
ListItem listitem = new ListItem();
listitem.Text = (string) dr["Name"];
listitem.Value = (string)dr["Name"];
ddPropertyType.Items.Add(listitem);
}
dr.Close();
by changing it like this:
ddPropertyType.Items.Clear();
ListItem li = new ListItem();
li.Text = "Any";
li.Value = "Any";
ddPropertyType.Items.Add(li);
using (IDataReader dr = mojoPortal.Business.DatabaseHelper.GetReader("select Name from propertytype"))
{
while (dr.Read())
{
ListItem listitem = new ListItem();
listitem.Text = (string) dr["Name"];
listitem.Value = (string)dr["Name"];
ddPropertyType.Items.Add(listitem);
}
}
this will close the connection even if an error happens
I realize only some of this feedback pertains to your issue about the error, but the suggestions at the beginning may help with that.
Also setting break points and stepping through the code may reveal where the problem is happening.
Best,
Joe