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 ?
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 C# windows form project with five read only text boxes.
When a box is clicked a textbox specific list box becomes visible for selection which closes once something is selected from that listbox and written to the textbox.
I have also been able to make it so that any open listboxes are not visible, if another textbox is selected.
What I need help with is how to make sure all listboxes are not visible if anything other than the textboxes on the form is selected eg buttons, other text boxes, menus etc.
I wondered if there was a more efficient way to do this than calling a method which ensures all listboxes are not visible, from every defined event on the form .
Thanks
Apologies but should have entered more detail and oversimplified things.
In fact the text boxes activate panels with a list box and buttons which modify that listbox.
I have tried leave event handlers on both the panel and listbox but neither seem to work when you click anywhere other than the textboxes. If you put a leave event on the text boxes, you don't get the opportunity to select anything from the list box as the panel is closed.
Code is as follows
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = false;
}
private void textBox2_MouseDown(object sender, MouseEventArgs e)
{
panel1.Visible = true;
panel2.Visible = false;
}
private void textBox3_MouseDown(object sender, MouseEventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox2.Text = listBox1.SelectedItem.ToString();
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
textBox3.Text = listBox2.SelectedItem.ToString();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
panel2.Visible = false;
}
private void listBox1_Leave(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void listBox2_Leave(object sender, EventArgs e)
{
panel2.Visible = false;
}
private void panel1_Leave(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void panel2_Leave(object sender, EventArgs e)
{
panel2.Visible = false;
}
}
}
Thanks again
You can control the visibility of multiple Controls by binding their Visible property to a common variable. In the Visual Studio designer, select the textbox and look at its properties. There is a section labeled DataBindings, and under that an (Advanced) option. Click that, and you will see a list of properties available for binding. Select the Visibility property and choose an existing boolean variable (as a Project data source) to associate with it. You can use the same variable to bind to the Visibile property of several textboxes. When your program logic sets that variable to True or False, the group of textboxes should appear/disappear accordingly.
I think I have in fact solved this with a bit of perseverence
To précis, two textboxes open individual panels with buttons and a listbox. Buttons within the panel will modify the listbox and when a selection is made in the listbox it is written to the same read only textbox. My problem was I needed to have these panels close if a selection was not made and a user went to another part of the form.
I have tried all combinations, and the solution seems to be to set focus on the panel when it is opened by textbox click event, and then have a panel leave event which makes the panel not visible. I also needed to make panels non visible with a form click event.
The final code is as follows:
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.Visible = false;
panel2.Visible = false;
}
private void textBox2_MouseDown(object sender, MouseEventArgs e)
{
panel1.Visible = true;
panel2.Visible = false;
panel1.Focus();
}
private void textBox3_MouseDown(object sender, MouseEventArgs e)
{
panel1.Visible = false;
panel2.Visible = true;
panel2.Focus();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox2.Text = listBox1.SelectedItem.ToString();
panel1.Visible = false;
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
textBox3.Text = listBox2.SelectedItem.ToString();
panel2.Visible = false;
}
private void panel1_Leave(object sender, EventArgs e)
{
panel1.Visible = false;
}
private void panel2_Leave(object sender, EventArgs e)
{
panel2.Visible = false;
}
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
panel1.Visible = false;
panel2.Visible = false;
}
}
}
Here's what H have so far:
private void button1_Click(object sender, EventArgs e)
{
button3.BackgroundImage = slideshow_test.Properties.Resources.ai_yori_aoshi_5370;
}
private void button2_Click(object sender, EventArgs e)
{
button3.BackgroundImage = slideshow_test.Properties.Resources.AiYoriAoshi_feature;
}
private void button3_Click(object sender, EventArgs e)
{
audio.Stop();
if (button1.Enabled == true)
{
timer1.Stop();
pictureBox1.Visible = false;
System.Diagnostics.Process.Start("http://www.watchcartoononline.com/anime/ai-yori-aoshi-guide");
if (button2.Enabled == true)
{
timer1.Stop();
pictureBox1.Visible = false;
System.Diagnostics.Process.Start("http://www.watchcartoononline.com/anime/ai-yori-aoshi-enishi-guide");
}
}
}
this is only my test so far but what i want to do is change what button 3 does, i.e. if button 1 is clicked button three will open webpage 1, if button2 is clicked button 3 will open webpage 2, button 3's image will change depending, but what im finding with what i have done so far is that it opens BOTH pages AT THE SAME TIME ... how to i prevent this? i have tried if, else and else if, same result every time.
Both of your buttons are enabled, you are checking to see if the buttons are enabled or disabled (clickable or not), not which one has been clicked.
also:if (button2.Enabled == true)
is nested in the first conditional, I'm not sure if that's what you want.
You can: disable buttons 1 and 2 after their clicked so that, for instance button2.Enabled will now = false; (but then you will not be able to reclick that button)
More sophisticated, but better, is to use a delegate for the button3, and assign them in your button1_Click and button2_Click events. Something like this:
private void button1_Click(object sender, EventArgs e)
{
button3.BackgroundImage = slideshow_test.Properties.Resources.ai_yori_aoshi_5370;
button3.Click += new EventHandler(this.Button3_Click_First);
}
private void button2_Click(object sender, EventArgs e)
{
button3.BackgroundImage = slideshow_test.Properties.Resources.AiYoriAoshi_feature;
button3.Click += new EventHandler(this.Button3_Click_Second);
}
void Button3_Click_First(Object sender,
EventArgs e)
{
// When the button is clicked,
// change the button text, and disable it.
timer1.Stop();
pictureBox1.Visible = false;
System.Diagnostics.Process.Start("http://www.watchcartoononline.com/anime/ai-yori-aoshi-guide");
}
void Button3_Click_Second(Object sender,
EventArgs e)
{
timer1.Stop();
pictureBox1.Visible = false;
System.Diagnostics.Process.Start("http://www.watchcartoononline.com/anime/ai-yori-aoshi-enishi-guide");
}
You may also have to check and make sure an event handler was not previously assigned, in calse someone clicks button1, then button2, then button1 ect. This is described here: Removing event handlers
You can handle your problem by storing the URL of the webpage in a private field, setting it when buttons 1 or 2 are clicked and reading from it after clicking button 3.
private string _address = null;
private void button1_Click(object sender, EventArgs e)
{
// do other stuff
_address = "http://www.watchcartoononline.com/anime/ai-yori-aoshi-guide";
}
private void button2_Click(object sender, EventArgs e)
{
// do other stuff
_address = "http://www.watchcartoononline.com/anime/ai-yori-aoshi-enishi-guide";
}
private void button3_Click(object sender, EventArgs e)
{
if (_address != null)
{
audio.Stop();
if (button1.Enabled || button2.Enabled)
{
timer1.Stop();
pictureBox1.Visible = false;
System.Diagnostics.Process.Start(_address);
}
}
}
I wasn't sure if all the code in button3_Click is necessary, so I cleared it up a little. I might be a bit off, though.
button.Enabled is always true for all buttons by default unless you set it to false. So you cannot use button1.Enabled property to check which button is pressed. try below approach.
protected void Button1_Click(object sender, EventArgs e)
{
ViewState["Button1Clicked"] = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
ViewState["Button1Clicked"] = false;
}
protected void Button3_Click(object sender, EventArgs e)
{
if ((bool)ViewState["Button1Clicked"])
{
//open webpage2 code comes here
}
else
{
//open webpage2 code comes here
}
}
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;
}
I am stuck on something: I am creating a hyperlink at runtime that has a navigation URL. I need to define its click event so that I can save a few values to the database. I did something like below but without success.
Could you please suggest an alternative?
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) {
if (e.Item is GridDataItem) {
HyperLink link = (HyperLink)gridDataItem["ContentTitle"].Controls[0];
link.ForeColor = System.Drawing.Color.Navy;
link.ToolTip = Common.grdTextCell(gridDataItem["ContentSummaryDescr"].Text);
link.NavigateUrl = "~/SomePath/" + gridDataItem["ContentName"].Text;
link.Target = "_blank";
link.Attributes.Add("onclick", "document.getElementById('" +
dummyBtn.ClientID + "').click();");
}
}
protected void dummyBtn_Click(object sender, EventArgs e) {
}
But the button click event is not firing, it simply navigates to the URL. What to do please?
For a server side event to fire you would need a LinkButton and not a HyperLink
LinkButton has a Click event handler which you can use.
HyperLink only redirects and has no corresponding Click event handler associated for server side code
You want a LinkButton, not a HyperLink.
Here's some sample code to get you started (not tested)
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
LinkButton link = (LinkButton)gridDataItem["ContentTitle"].Controls[0];
link.Click += dummyBtn_Click;
}
}
protected void dummyBtn_Click(object sender, EventArgs e)
{
Response.Write("dummyBtn_Click");
}
You should be using Link Button. Just replace your Hyperlink with LinkButton in your code.It should work.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) {
if (e.Item is GridDataItem) {
LinkButton link = (LinkButton )gridDataItem["ContentTitle"].Controls[0];
link.ForeColor = System.Drawing.Color.Navy;
link.ToolTip = Common.grdTextCell(gridDataItem["ContentSummaryDescr"].Text);
link.NavigateUrl = "~/SomePath/" + gridDataItem["ContentName"].Text;
link.Target = "_blank";
link.Click += dummyBtn_Click;
}
}
protected void dummyBtn_Click(object sender, EventArgs e) {
}