Hello everyone,
Iam firing a event in the chechbox_checke dchanged. It works fine -
private void checkBox1_CheckedChanged(object sender, EventArgs e)
-
{
-
/
-
textBox1.Visible = false;
-
textBox2.Visible = false;
-
button2.Visible = false;
-
-
String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
-
-
using (OleDbConnection connection = new OleDbConnection(connectionString))
-
{
-
OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
-
-
connection.Open();
-
OleDbDataReader reader = command.ExecuteReader();
-
if (reader.HasRows)
-
{
-
while (reader.Read())
-
{
-
String rea = reader[0].ToString();
-
String reb = reader[1].ToString();
-
MessageBox.Show("Username and Password are Matching Click ok to continue ..");
-
groupBox2.Visible = false;
-
groupBox1.Visible = false;
-
groupBox3.Visible = true;
-
checkBox1.Checked = false;
-
newop(rea, reb, out res1, out res2);
-
}
-
}
-
else
-
{
-
MessageBox.Show("No Record please provide username and pwd");
-
groupBox2.Visible = true;
-
textBox1.Visible = true;
-
textBox2.Visible = true;
-
button2.Visible = true;
-
checkBox1.Checked = false;
-
groupBox1.Visible = false;
-
}
-
reader.Close();
-
connection.Close();
-
}
-
}
-
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.
4 4271
Hello everyone,
Iam firing a event in the chechbox_checke dchanged. It works fine -
private void checkBox1_CheckedChanged(object sender, EventArgs e)
-
{
-
-
textBox1.Visible = false;
-
textBox2.Visible = false;
-
button2.Visible = false;
-
-
String connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + datapath + "'";
-
-
using (OleDbConnection connection = new OleDbConnection(connectionString))
-
{
-
OleDbCommand command = new OleDbCommand("select * from userinfo WHERE ServerUrl='" + temp + "'", connection);
-
-
connection.Open();
-
OleDbDataReader reader = command.ExecuteReader();
-
if (reader.HasRows)
-
{
-
while (reader.Read())
-
{
-
String rea = reader[0].ToString();
-
String reb = reader[1].ToString();
-
MessageBox.Show("Username and Password are Matching Click ok to continue ..");
-
groupBox2.Visible = false;
-
groupBox1.Visible = false;
-
groupBox3.Visible = true;
-
checkBox1.Checked = false;
-
newop(rea, reb, out res1, out res2);
-
}
-
}
-
else
-
{
-
MessageBox.Show("No Record please provide username and pwd");
-
groupBox2.Visible = true;
-
textBox1.Visible = true;
-
textBox2.Visible = true;
-
button2.Visible = true;
-
checkBox1.Checked = false;
-
groupBox1.Visible = false;
-
}
-
reader.Close();
-
connection.Close();
-
}
-
}
-
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.
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: - if(checkbox1.checked == true)
-
{
-
//execute code
-
}
-
else
-
{
-
return;
-
}
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
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.
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 ....
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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:
|
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'...
|
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.
|
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);
| |
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:
|
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
|
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>
|
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);
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |