473,668 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

checkbox eventhandler visual c# 2008

69 New Member
Hello everyone,

Iam firing a event in the chechbox_checke dchanged. It works fine
Expand|Select|Wrap|Line Numbers
  1.  private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2.         {
  3.             /
  4.                 textBox1.Visible = false;
  5.                 textBox2.Visible = false;
  6.                 button2.Visible = false;
  7.  
  8.                 String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
  9.  
  10.                 using (OleDbConnection connection = new OleDbConnection(connectionString))
  11.                 {
  12.                     OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
  13.  
  14.                     connection.Open();
  15.                     OleDbDataReader reader = command.ExecuteReader();
  16.                     if (reader.HasRows)
  17.                     {
  18.                         while (reader.Read())
  19.                         {
  20.                             String rea = reader[0].ToString();
  21.                             String reb = reader[1].ToString();
  22.                             MessageBox.Show("Username and Password are Matching Click ok to continue ..");
  23.                             groupBox2.Visible = false;
  24.                             groupBox1.Visible = false;
  25.                             groupBox3.Visible = true;
  26.                             checkBox1.Checked = false;
  27.                             newop(rea, reb, out res1, out res2);
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         MessageBox.Show("No Record please provide username and pwd");
  33.                         groupBox2.Visible = true;
  34.                         textBox1.Visible = true;
  35.                         textBox2.Visible = true;
  36.                         button2.Visible = true;
  37.                         checkBox1.Checked = false;
  38.                         groupBox1.Visible = false;
  39.                     }
  40.                     reader.Close();
  41.                     connection.Close();
  42.                 }
  43.   }
  44.  
The problem after this event when i make the checkbox visible the checkbox is in checked state. so if i make the checkbox.checke dstate= false automatically the else part in the chekedchanged event is triggering i know why it is happening?.. what are the other ways i can make the checkbox in unchecked state without firing this eventhandler or should i write the code in someother handler event of checkbox ?..

Thank you.

Dinesh.
Feb 18 '09 #1
4 4271
sarabonn
69 New Member
Hello everyone,

Iam firing a event in the chechbox_checke dchanged. It works fine
Expand|Select|Wrap|Line Numbers
  1.  private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2.         {
  3.  
  4.                 textBox1.Visible = false;
  5.                 textBox2.Visible = false;
  6.                 button2.Visible = false;
  7.  
  8.                 String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
  9.  
  10.                 using (OleDbConnection connection = new OleDbConnection(connectionString))
  11.                 {
  12.                     OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
  13.  
  14.                     connection.Open();
  15.                     OleDbDataReader reader = command.ExecuteReader();
  16.                     if (reader.HasRows)
  17.                     {
  18.                         while (reader.Read())
  19.                         {
  20.                             String rea = reader[0].ToString();
  21.                             String reb = reader[1].ToString();
  22.                             MessageBox.Show("Username and Password are Matching Click ok to continue ..");
  23.                             groupBox2.Visible = false;
  24.                             groupBox1.Visible = false;
  25.                             groupBox3.Visible = true;
  26.                             checkBox1.Checked = false;
  27.                             newop(rea, reb, out res1, out res2);
  28.                         }
  29.                     }
  30.                     else
  31.                     {
  32.                         MessageBox.Show("No Record please provide username and pwd");
  33.                         groupBox2.Visible = true;
  34.                         textBox1.Visible = true;
  35.                         textBox2.Visible = true;
  36.                         button2.Visible = true;
  37.                         checkBox1.Checked = false;
  38.                         groupBox1.Visible = false;
  39.                     }
  40.                     reader.Close();
  41.                     connection.Close();
  42.                 }
  43.   }
  44.  
The problem after this event when i make the checkbox visible the checkbox is in checked state. so if i make the checkbox.checke dstate= false automatically the else part in the chekedchanged event is triggering i know why it is happening?.. what are the other ways i can make the checkbox in unchecked state without firing this eventhandler or should i write the code in someother handler event of checkbox ?..

Thank you.

Dinesh.
Feb 18 '09 #2
cloud255
427 Recognized Expert Contributor
Hi

By reading your code it seems that you only want to execute this section if the check box is checked (in both the if and else you set the checked to false).

a work around might be to check if the textbox is checked before executing the code:

Expand|Select|Wrap|Line Numbers
  1. if(checkbox1.checked == true)
  2. {
  3.   //execute code
  4. }
  5. else
  6. {
  7.   return;
  8. }
if indeed you want the code to execute each time the checked state changes, i suggest you use a Boolean variable (not inside the event handler scope) to perform a similar task as described above. Neither of these methods is optimal as they both cause the event to fire more than once per user interaction.

Ultimately i would suggest that you use a command button to execute code that reads from the database, but that is a personal preference in design choice.

Good luck
Feb 18 '09 #3
Frinavale
9,735 Recognized Expert Moderator Expert
Add an if statement around your whole code checking if the checkbox is checked before executing the call to the database.

If it's not checked, don't do anything.
If it is, execute the code.
Feb 18 '09 #4
tlhintoq
3,525 Recognized Expert Specialist
[edit] Threads have been merged[/edit]

By the way, another technique for your need to would be to disconnect the event, change the checkbox, then reconnect the event.

.... -= new eventhandler ......
mycheckbox.chec ked = false;
... += new eventhandler ....
Feb 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2329
by: Tomas Vera | last post by:
Hello All, I'm having problems creating a page with dynamic checkboxes in a WebApp. In my app, I need to query a database, then (based on results) add checkboxes to my form and set their "Checked" state. Since the controls are dynamically created, I'm using the OnInit event to create the checkboxes and set the "Checked" state from the DB. Next, I want to capture the postback event (AutoPostBack=true) and update my database based on...
2
11786
by: Thomas R | last post by:
Is is possible? In VS.NET 2003, Binding data to the repeater is easy, but when I try to add an ASP:checkbox to the .aspx page, the designer won't recognize it, hence the code view doesn't allow me to access it. The funny thing is that it compiles fine, and the checkboxes are there, I just can't write to them! Is there a way around this problem? My HTML is as follows:
4
5944
by: mahsa | last post by:
my problem dosent solve yet I want to have claa void in onclick of my check bov if I us function setProps ( ) msg.innerText = "llll"; in <datalist> <ItemTemplate><input type="checkbox" id="cbItem" runat="server" onclick="test() value='<%#DataBinder.Eval(Container.DataItem, "PartNo")%>' NAME="cbItem"><%#DataBinder.Eval(Container.DataItem, "PartNo")%><td class='item_content' width='83'><input value=4 maxLength='4' size='4'...
5
3007
by: TPS | last post by:
I have a checkbox column in my datagrid. This checkbox triggers an autopostback. When I postback, I need to tell what row the user is on so I can tell what check box was checked or unchecked. Can't seem to find that property. Thanks.
6
1544
by: Alessandro Rossi | last post by:
Hi, I have to create a CheckBox, and i would like will be checked if there is a value in a property added, and not checked if there is another value. I added 2 property (string) to the checkbox; the first , CheckedValue is the value for whom i want the check will be checked. The second is the opposite. I Added a handler to the checkbox in this way: this.DataBinding+=new EventHandler(AreaITWebCheckBox_DataBinding);
2
6410
by: Nu2ASP.NET | last post by:
What I am trying to do is essentially 'flip' the bits, when the user clicks in the checkbox. For example, if the CheckBox appears checked, and the user un-checks it, I want the underlying data field to change from a "1" to a "0" (and vica versa). I have the bindings worked out, I just can't figure out how to do the update. Here is my source:
2
2704
by: Javier | last post by:
Hi Everyone, I have a dynamic checkbox in a datagrid that uses the ITemplate interface and has the checkchanged event wired up. When the checkbox is checked, the event event handler that handles the event gets called, however when it is unchecked, it does not fire. Is this by design, or is something else that is going on? Thanks!!. This message was originally posted by marian@discussions.microsoft.com, but
1
1820
by: Jason Huang | last post by:
Hi, In my ASPNET 2.0 C# Web form, what's the difference between a CheckBox and a TemplateField's CheckBox? <asp:CheckBox id="CheckBoxNormal" runat="server" AutoPostBack="True" /> <asp:TemplateField HeaderText="Select"> <ItemTemplate>
4
3797
by: darkminos | last post by:
Hi, I am creating dynamic checkboxes which should have an eventhandler attached to the submitButton. What I mean is while I’m changing state (check / uncheck) nothing should be happening but when I press the submitButton it should read all the checkboxes state and text. Thx. SimpleButton submitButton = new SimpleButton(); submitButton.Location = new System.Drawing.Point(292, (29 + countMachines * 21) + 181);
0
8459
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
8374
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
8890
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
8791
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
7398
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...
1
6206
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2784
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
2
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.