473,672 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strange problem of Dynamic Checkbox

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(objec t sender, System.EventArg s e)
{
if(!IsPostBack)
{
get_servc();
}
}
override protected void OnInit(EventArg s e)
{
InitializeCompo nent();
base.OnInit(e);
if (Page.IsPostBac k)
{
Session.Timeout =120;
_checkboxes = (ArrayList) Session["CheckBoxAr ray"];
}
else
{
_checkboxes = new ArrayList();
get_servc();
}

foreach(CheckBo x c1 in _checkboxes)
Panel1.Controls .Add(c1);
}
public void get_servc()
{
strcatgy = Convert.ToStrin g(Session["Category"]);
string temp = strcatgy;
int xPos = 20;
int yPos= 335;
int count=0;
objcmd = new SqlCommand("Sel ectDynControls" , objConn);
objcmd.CommandT ype = CommandType.Sto redProcedure;
objConn.Open();
objRdr=objcmd.E xecuteReader();
while(objRdr.Re ad())
{
CheckBox c1 = new CheckBox();
c1.ID="chk" + _checkboxes.Cou nt.ToString();
c1.AutoPostBack =true;
c1.Visible=true ;
c1.Text = Convert.ToStrin g(objRdr["CbName"]);
if(c1.Text == temp)
{
c1.Checked=true ; // this is the part which is not working
}

c1.Style.Add("D ISPLAY", "BLOCK");
if((count % 6)==0)
{
yPos +=30;
xPos =20;
}
c1.Style.Add("P OSITION", "absolute") ;
c1.Style.Add("T OP", Convert.ToStrin g(yPos));
c1.Style.Add("L EFT", Convert.ToStrin g(xPos));
_checkboxes.Add (c1);
Panel1.Controls .Add(c1);
xPos += 120;
count += 1;
}
objRdr.Close();
objConn.Close() ;
yPos = yPos + 50;
xPos = 275;
}

Nov 19 '05 #1
1 1269
Actually the code had no problem
As I was creating the dynamic controls prior to page load. we have to
call method get_servc() again as shown in my code below
and now its working
hope this will be of some help to the people who stuck with the same
problem
private void dl_Edit(object source,
System.Web.UI.W ebControls.Data ListCommandEven tArgs e)
{
strcatgy =((Label)e.Item .FindControl("l blcategory")).T ext;
Session["Category"]= strcatgy;
get_servc();
............
...........
............
}

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2136
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see "TAG#") when more than 1 number (see "VLANS") is inputed into my form. QUESTION: How do I make my dynamic form have a dynamic input box(which is created by checking the checkbox and calling the functionC1) inside it and still be able to pass the...
3
3973
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
5
4020
by: Irfan Akram | last post by:
Hi Mr.Steve, First of all many thanks for your kind response. The thing is that I am trying to control the user's action of deselecting a checkbox, once he has selected it. Also the checkbox has been generated dynamically. If it is selected I do some other processing, so if it is then deselected then the whole page has to be resetted, hence the sense of displaying the warning message. The problem is that I dont want the warning message...
11
1912
by: Dagwood Bumstead | last post by:
I play around with js a little... I just don't get this. The file below is just trying out some things... it does exactly what I want (hides/displays some things, no big deal) The problem is that in the swapcheck(x) function below, if I uncomment the first line (commented with //) the whole thing brings and IE errors the page with an object expected error on line (whichever input control I clicked).
3
1906
by: Raymond | last post by:
I am having a problem about the dynamic checkbox Private Sub Page_Load Me.NumberOfChkControls = 0 Dim cbCheckBox As New CheckBox cbCheckBox.Text = .Id.ToString cbCheckBox.ID = "ControlID_" + NumberOfChkControls.ToString NumberOfChkControls = NumberOfChkControls + 1 cbCheckBox.EnableViewState = True dimNewTableCell.Controls.Add(cbCheckBox) dimNewTableRow.Cells.Add(dimNewTableCell)
0
1342
by: =?Utf-8?B?SWRlcm9ja3M=?= | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in different event...
1
6013
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in a different event...
2
2630
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8680
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.