I have got problem with check-box to enable corresponding control next to it. My Requirement is at the page load we want to disable the all textboxes and dropdownlists by using checkbox
if the check-box is checked the control next to that check-box will be enabled for that i have done like this....
at page load
i have written like this
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
}
and then in checkbox check changed event i have written like this
protected void ChckOrdType_CheckChanged(object sender, EventArgs e)
{
if (ChckOrdType.Checked)
ddlOrdType.Enabled = true;
else
ddlOrdType.Enabled = false;
}
protected void chkPlntPric_CheckChanged(object sender, EventArgs e)
{
if (ChkPlntPric.Checked)
ddlPlntPric.Enabled = true;
else
ddlPlntPric.Enabled = false;
}
protected void chkExcluBro_CheckChanged(object sender, EventArgs e)
{
if (ChkExcluBro.Checked)
ddlExcluBroker.Enabled = true;
else
ddlExcluBroker.Enabled = false;
}
but results is like this ...
I am getting checkbox not checked and control next to it is enabled...But this not what i want
My results is if the check-box is not checked the control next to it is disabled
would any one pls help on this....
Thanks In advance......
This is because you have just wrote ONLY to uncheck the checkboxes in the pageload and not to disable the controls behind the checkbox; If thats needed, then your snippet in the pageload should be:
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
ddlOrdType.Enabled = false;
ddlPlntPric.Enabled = false;
ddlExcluBroker.Enabled = false;
.........
}
or
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
......
.....
ChckOrdType_CheckChanged(sender,e);
chkPlntPric_CheckChanged(sender,e);
chkExcluBro_CheckChanged(sender,e);
...
}
Disable text boxes in page load like below.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ChckOrdType.Checked = false;
ChkPlntPric.Checked = false;
ChkExcluBro.Checked = false;
DisableFirstTime();
......
.....
}
private void DisableFirstTime()
{
ddlOrdType.Enabled = false;
ddlPlntPric.Enabled = false;
ddlExcluBroker.Enabled = false;
}
Related
done this function
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[1].Visible = false;
e.Row.Cells[3].Visible = false;
}
want change this function on button click event or jquery function.
protected void btn_POPUP_Click1(object sender, EventArgs e)
{
e.Row.Cells[1].Visible = true;
e.Row.Cells[3].Visible = true;
}
this is not working know more please guide.
I have a asp.net page with a grid and, above the grid, fields showing the contents of the highlighted row and some buttons (edit, add, delete, etc...).
If the user clicks the edit button then it enables the fields for editing.
However, after enabling the fields the grid is then refreshed or something and the first row is then highlighted and the fields on the screen changes. Why? How do I stop this?
Code is below:
protected void btnEdit_Click(object sender, EventArgs e)
{
ChangeButtons(null, EventArgs.Empty);
ChangeFields(null, EventArgs.Empty);
updatetype = "Edit";
}
protected void ChangeButtons(object sender, EventArgs e)
{
btnAdd.Enabled = !btnAdd.Enabled;
btnCopy.Enabled = !btnCopy.Enabled;
btnEdit.Enabled = !btnEdit.Enabled;
btnDelete.Enabled = !btnDelete.Enabled;
btnCancel.Enabled = !btnCancel.Enabled;
btnSave.Enabled = !btnSave.Enabled;
btnClose.Enabled = !btnClose.Enabled;
btnSearchCredits.Enabled = !btnSearchCredits.Enabled;
btnClearCredits.Enabled = !btnClearCredits.Enabled;
}
protected void ChangeFields(object sender, EventArgs e)
{
txtSrchCredible_ID.Enabled = !txtSrchCredible_ID.Enabled;
txtSrchADP_ID.Enabled = !txtSrchADP_ID.Enabled;
txtSrchStart_Date.Enabled = !txtSrchStart_Date.Enabled;
txtSrchEnd_Date.Enabled = !txtSrchEnd_Date.Enabled;
txtCredible_ID.Enabled = !txtCredible_ID.Enabled;
txtADP_ID.Enabled = !txtADP_ID.Enabled;
txtEmployee_ID.Enabled = !txtEmployee_ID.Enabled;
txtStart_Date.Enabled = !txtStart_Date.Enabled;
txtEnd_Date.Enabled = !txtEnd_Date.Enabled;
txtReason.Enabled = !txtReason.Enabled;
txtUnits.Enabled = !txtUnits.Enabled;
txtPercentage.Enabled = !txtPercentage.Enabled;
txtOther.Enabled = !txtOther.Enabled;
}
First I gave to my first button the CommandArguments
btnDateModif.CommandArgument = hebergement.Attributes["IdInterne"].Value;
Then I'm using the button like this
protected void BtnModifDate_Click(object sender, CommandEventArgs e)
{
PanelModifDate.Visible = true;
PanelHebergement.Visible = false;
}
protected void BtnEnregistreDate_Click(object sender, CommandEventArgs e)
{
CheckValidDate();
PanelModifDate.Visible = false;
PanelHebergement.Visible = true;
}
My question is how I can give the CommandArgument of the first button to the other one ?
The Default is No Checkbox
When I run the program and Click the Yes Checkbox the program overflowed
private void checkEdit1_Click(object sender, EventArgs e)
{
checkEdit2.Checked = false;
textEdit1.Enabled = true;
answered = true;
optional = textEdit1.Text;
if (!checkEdit1.Checked)
{
checkEdit1.Checked = true;
checkEdit2.Checked = false;
textEdit1.Enabled = true;
optional = textEdit1.Text;
}
}
private void checkEdit2_Click(object sender, EventArgs e)
{
checkEdit1.Checked = false;
textEdit1.Enabled = false;
answered = false;
if (!checkEdit2.Checked)
{
checkEdit2.Checked = true;
checkEdit1.Checked = false;
textEdit1.Enabled = false;
answered = false;
}
}
What you think is the error ?
Instead of the Click event you should use the CheckedChanged event in this way:
checkEdit1.CheckedChenged += new EventHandler(checkEdit1_CheckedChanged);
checkEdit2.CheckedChenged += new EventHandler(checkEdit2_CheckedChanged);
private void checkEdit1_CheckedChanged(object sender, EventArgs e)
{
if(checkEdit1.Checked == checkEdit2.Checked)
checkEdit2.Checked = !checkEdit.Checked;
}
private void checkEdit2_CheckedChanged(object sender, EventArgs e)
{
if(checkEdit1.Checked == checkEdit2.Checked)
checkEdit2.Checked = !checkEdit.Checked;
}
But the best way in this case is to use a group of radio buttons.
Assuming that those methods are wired up to checkEdit1 and checkEdit2 I would advise that you don't make a change to checkEdit1 in checkEdit1_Click as it has already changed - only modify the state of the alternate.
However, when you modify the state of the other, unless you're careful, you're going to get called back. Eventually the computer gives up -- the overflow!
As mentioned in a comment by #Cyborgx37, radio buttons are the better UX choice here!
A possible solution, bind a single method to the OnClick to BOTH checkboxes:
private bool internallyUpdating = false;
private void CheckboxClick(object sender, EventArgs e)
{
if ( !internallyUpdating )
{
// Prevent subsequent changes
internallyUpdating = true;
// Exchange 'checked' state
if ( sender == checkEdit1 )
{
checkEdit2.Checked = !checkEdit2.Checked;
}
else // if (sender == checkEdit2)
{
checkEdit1.Checked = !checkEdit1.Checked;
}
// other logic here..
// restore 'on change' functionality.
internallyUpdating = false;
}
I have created gui for windows form....!
one side i have groupbox with checkbox and two buttons ">>" and "<<" and on the other side i have one more groupbox.
I need to select one checkbox at a time if the user select more than one checkbox i need to raise error..
if the user selects checkbox and click on ">>" button i need to display number of messages in the other groupbox i.e in the "List of Selected Commands"...
and on the click of ">>" the selected list of message should be deleted from list.
I have included tab control in my gui on click of this tab i need to display some list of commands how can i do it...
can any one help me on this...
This is the code..
namespace Menu_Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
groupBox1.Text = "MSC";
groupBox2.Text = "List Of Selected Commands";
checkBox1.Visible = false;
cb2.Visible = false;
cb3.Visible = false;
cb4.Visible = false;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
label4.Visible = false;
}
private void submenu1ToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "ICP";
checkBox1.Visible = true;
cb2.Visible = true;
cb3.Visible = true;
cb4.Visible = true;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
label1.Visible = true;
label1.Text = "ibit";
groupBox2.Controls.Add(label1);
label2.Visible = true;
label2.Text = "Cbit";
groupBox2.Controls.Add(label2);
label3.Visible = true;
label3.Text = "Kbit";
groupBox2.Controls.Add(label3);
label4.Visible = true;
label4.Text = "ibit";
groupBox2.Controls.Add(label4);
}
if (cb2.Checked == true)
{
label1.Visible = true;
label1.Text = "ibit";
groupBox2.Controls.Add(label1);
label2.Visible = true;
label2.Text = "Cbit";
groupBox2.Controls.Add(label2);
label3.Visible = true;
label3.Text = "Kbit";
groupBox2.Controls.Add(label3);
label4.Visible = true;
label4.Text = "ibit";
groupBox2.Controls.Add(label4);
}
}
private void btn6_Click(object sender, EventArgs e)
{
if (label1.Enabled==true)
{
label1.Text = "";
}
}
private void btn5_Click(object sender, EventArgs e)
{
label1.Text = "";
label2.Text = "";
label3.Text = "";
label4.Text = "";
}
private void submenu2ToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MCP";
}
private void mDPToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MDP";
}
private void mRPPToolStripMenuItem_Click(object sender, EventArgs e)
{
groupBox1.Text = "MRPP";
}
}
}
I am giving you an idea, that how we can do that.
You have to create a group box click event and then use loop for the controls in that groupbox and if that control is checkbox and it is checked, then you just count that no-other checkbox should be checked.
I will be available with the code very shortly.