S
savvy
I'm comparing two strings and trying to check a dynamic checkbox when
its true on pageload , but i dont know why i'm not able to do that on
page load, when i click some other links and come back to this page
then the required checkbox will be checked. I'm not able to figure out
where is the problem. Sorry about the long code
Any help will be greatly appreciated
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
get_servc();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
if (Page.IsPostBack)
{
Session.Timeout=120;
_checkboxes = (ArrayList) Session["CheckBoxArray"];
}
else
{
_checkboxes = new ArrayList();
get_servc();
}
foreach(CheckBox c1 in _checkboxes)
Panel1.Controls.Add(c1);
}
public void get_servc()
{
strcatgy = Convert.ToString(Session["Category"]);
string temp = strcatgy;
int xPos = 20;
int yPos= 335;
int count=0;
objcmd = new SqlCommand("SelectDynControls", objConn);
objcmd.CommandType = CommandType.StoredProcedure;
objConn.Open();
objRdr=objcmd.ExecuteReader();
while(objRdr.Read())
{
CheckBox c1 = new CheckBox();
c1.ID="chk" + _checkboxes.Count.ToString();
c1.AutoPostBack=true;
c1.Visible=true;
c1.Text = Convert.ToString(objRdr["CbName"]);
if(c1.Text == temp)
{
c1.Checked=true; // this is the part which is not working
}
c1.Style.Add("DISPLAY", "BLOCK");
if((count % 6)==0)
{
yPos +=30;
xPos =20;
}
c1.Style.Add("POSITION", "absolute");
c1.Style.Add("TOP", Convert.ToString(yPos));
c1.Style.Add("LEFT", Convert.ToString(xPos));
_checkboxes.Add(c1);
Panel1.Controls.Add(c1);
xPos += 120;
count += 1;
}
objRdr.Close();
objConn.Close();
yPos = yPos + 50;
xPos = 275;
}
its true on pageload , but i dont know why i'm not able to do that on
page load, when i click some other links and come back to this page
then the required checkbox will be checked. I'm not able to figure out
where is the problem. Sorry about the long code
Any help will be greatly appreciated
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
get_servc();
}
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
if (Page.IsPostBack)
{
Session.Timeout=120;
_checkboxes = (ArrayList) Session["CheckBoxArray"];
}
else
{
_checkboxes = new ArrayList();
get_servc();
}
foreach(CheckBox c1 in _checkboxes)
Panel1.Controls.Add(c1);
}
public void get_servc()
{
strcatgy = Convert.ToString(Session["Category"]);
string temp = strcatgy;
int xPos = 20;
int yPos= 335;
int count=0;
objcmd = new SqlCommand("SelectDynControls", objConn);
objcmd.CommandType = CommandType.StoredProcedure;
objConn.Open();
objRdr=objcmd.ExecuteReader();
while(objRdr.Read())
{
CheckBox c1 = new CheckBox();
c1.ID="chk" + _checkboxes.Count.ToString();
c1.AutoPostBack=true;
c1.Visible=true;
c1.Text = Convert.ToString(objRdr["CbName"]);
if(c1.Text == temp)
{
c1.Checked=true; // this is the part which is not working
}
c1.Style.Add("DISPLAY", "BLOCK");
if((count % 6)==0)
{
yPos +=30;
xPos =20;
}
c1.Style.Add("POSITION", "absolute");
c1.Style.Add("TOP", Convert.ToString(yPos));
c1.Style.Add("LEFT", Convert.ToString(xPos));
_checkboxes.Add(c1);
Panel1.Controls.Add(c1);
xPos += 120;
count += 1;
}
objRdr.Close();
objConn.Close();
yPos = yPos + 50;
xPos = 275;
}