Hello everyone,
Iam firing a event in the chechbox_checkedchanged. 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.checkedstate= 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 4265
Hello everyone,
Iam firing a event in the chechbox_checkedchanged. 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.checkedstate= 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.
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
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.
[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.checked = 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...
|
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...
|
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"...
|
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.
...
|
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;...
|
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...
|
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...
|
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" />
...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
| |