I don't know how to fix or handle this issue. But I currenlty have 2 links as following:
NavigateUrl="~/Admin/ManageProducts.aspx?IsMeal=true and False.
When it is set to TRUE I want txtDescription to be visible, and when set to FALSE I wan't txtDescription to be invisible.
IsMeal is a BIT in my database. So I need to define somehow that, when ManageProducts.aspx?IsMeal=true then txtDescription should be visible, and reverse
FALSE = invisible
But how do I manage this?
In your Page_Load() method you can add the following:
protected void Page_Load(object sender, EventArgs e) {
txtDescription.Visible = Convert.ToBoolean(Request.QueryString("IsMeal"));
}
In the ManageProducts.aspx.cs file place this:
protected void Page_Load(object sender, EventArgs e) {
if (Request.QueryString["IsMeal"] != null) {
if (Boolean.Parse(Request.QueryString["IsMeal"])) {
txtDescription.Visible = true;
}
else {
txtDescription.Visible = false;
}
}
}
Wouldn't you just set the property accordingly:
bool isMeal = Convert.ToBoolean(Request.QueryString["IsMeal"]);
txtDescription.Visible = isMeal;
Related
Well, I have this situation, in a program I put a Button whose code is activated with PerformClick (programmatically), that button must be invisible in the interface so I put the value visible=false since the beginning of the program but the action on the event click doesn't perform, but if I put visible = true, the action actually is performed, any ideas of the problem?
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
if(_datosDe == "Insumos")
{
_btnRecargarInsumos.PerformClick();
}
this.Close();
}
_btnRecargarInsumos: is the button and is actually performed in another Form.
private void btnRecargarInsumos_Click(object sender, EventArgs e)
{
objGeneral.regresaDescripciones(ref dsDescripciones);
cbACDescripcion.DataSource = dsDescripciones.Tables[0];
cbACDescripcion.DisplayMember = "Nombre";
cbACDescripcion.ValueMember = "ID";
cbACDescripcion.SelectedIndex = -1;
cbACDescripcion.Text = "";
}
cbACDescripcion: Combobox which will be "reloaded" with the values of the DataSet: dsDescripciones.
The property visible is false since the beginnig of the program, but I also try to set visible=true and just before the method PerformClick() change it, but is the same.
But if I put visible=true since the beginning it works in that way.
If you click a button that's not visible or not enabled, nothing happens, even if you click it programmatically. Here's a workaround that works for me, although it's a bit of a hack:
_btnRecargarInsumos.SuspendLayout();
_btnRecargarInsumos.Visible = true;
_btnRecargarInsumos.PerformClick();
_btnRecargarInsumos.Visible = false;
_btnRecargarInsumos.ResumeLayout();
Why not just put your code in a separate method?
Example:
private StuffToDoAtClick()
{
objGeneral.regresaDescripciones(ref dsDescripciones);
cbACDescripcion.DataSource = dsDescripciones.Tables[0];
cbACDescripcion.DisplayMember = "Nombre";
cbACDescripcion.ValueMember = "ID";
cbACDescripcion.SelectedIndex = -1;
cbACDescripcion.Text = "";
}
//Your Button.Click() code//
private void btnRecargarInsumos_Click(object sender, EventArgs e)
{
StuffToDoAtClick()
}
//Your Datagridview code//
private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
if(_datosDe == "Insumos")
{
StuffToDoAtClick();
}
this.Close();
}
I am creating a program using WinForms so users can input info into textboxes on one form which then are saved into a Listbox on another form. I would like to be able to edit the items saved in the listbox by opening the original form on a button click. Really struggling with it as I can't think of the code and I can't seem to find a solution.
My Code:
private void btnAdd_Click(object sender, EventArgs e)
{
RoomDisplayForm newRoomDisplayForm = new RoomDisplayForm();
newRoomDisplayForm.ShowDialog();
if(newRoomDisplayForm.DialogResult == DialogResult.OK)
{
listBoxRooms.Items.Add(newRoomDisplayForm.value);
}
newRoomDisplayForm.Close();
}
private void btnRemove_Click(object sender, EventArgs e)
{
this.listBoxRooms.Items.RemoveAt(this.listBoxRooms.SelectedIndex);
}
private void btnEdit_Click(object sender, EventArgs e)
{
}
So i've got a Add and Remove button which work perfectly just need a solution to the edit button.
Thanks in advance
I'm guessing newRoomDisplayForm.value is a property or a public member inside the form. You just need to do something like this:
private void btnEdit_Click(object sender, EventArgs e)
{
if(listBoxRooms.SelectedIndex < 0) return;
var tmpValue = listBoxRooms.Items[listBoxRooms.SelectedIndex].ToString();
RoomDisplayForm newRoomDisplayForm = new RoomDisplayForm();
newRoomDisplayForm.value = tmpValue;
newRoomDisplayForm.ShowDialog();
//TODO: inside "newRoomDisplayForm" set the value to the textbox
// ie.: myValueTextBox.Text = this.value;
if(newRoomDisplayForm.DialogResult == DialogResult.OK)
{
// replace the selected item with the new value
listBoxRooms.Items[listBoxRooms.SelectedIndex] = newRoomDisplayForm.value;
}
}
Hope it helps!
You can simply remove the listitem in that specific position, create a new item and add it again. it's kind of replacement.
I have a RichEditBox in a C# Windows Runtime app. I have set it to set a Boolean flag IsFileUpToDate to false on TextChanged like so:
private void OnTextChanged(object sender, RoutedEventArgs e)
{
if (IsFileUpToDate != false)
{
IsFileUpToDate = false;
}
}
When the page is first navigated to, IsFileUpToDate should be set to true. I have set it like so:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
IsFileUpToDate = true;
}
However, the RichEditBox gains focus immediately when the page loads, and this seems to be causing it set the Boolean to false even though the text hasn't been changed. Why is it doing this? How can I rewrite these commands so that the Boolean is reliably set?
RichEditBox is getting it's text changed on when it is loaded
you can have another flag to make sure it won't change yours on the fisrt time
private void OnTextChanged(object sender, RoutedEventArgs e)
{
if (IsFirstload)
{
IsFirstLoad = false;
return;
}
if (IsFileUpToDate != false)
{
IsFileUpToDate = false;
}
}
I have the following codes that is the button on and off:
private void OnActivity_Click(object sender, RoutedEventArgs e)
{
if ((sender as Button).Content.Equals("On"))
{
(sender as Button).Content = "Off";
}
else
{
(sender as Button).Content = "On";
}
}
I have another method named protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
How can I call the sender as Button of OnActivity_Click into another method ? I need to trigger On and Off then On again in the navigation method. Someone help me pls ! Thanks !
Inside OnNavigatedTo you can use the button reference. For example:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
OnActivity_Click(this.btn1, null);
}
Your button here has the name "btn1" (set it in xaml).
Give name to the button in xaml like x:name="btn"
and then use it in OnNavigatedTo method like this,
btn.content="On";
I want to validate the users changes on a page before allowing them to go to another page. If the validation fails I want to stop the pager from changing the page.
For example:
protected void rgOrderItem_PageIndexChanged(object source, GridPageChangedEventArgs e)
{
if (Mapvalues(false))
{
rgOrderItem.CurrentPageIndex = LastPageIndex;
rgOrderItem.DataBind();
}
}
This does not work. The pager changes regardless. Anyone know how to stop a page change event?
Thanks, Tony
Please try with the below code snippet.
protected void RadGrid1_PageSizeChanged(object sender, GridPageSizeChangedEventArgs e)
{
if (Mapvalues(false))
{
e.Canceled = true; //Prevent to execute pagging functionality
}
}
protected void RadGrid1_PageIndexChanged(object sender, GridPageChangedEventArgs e)
{
if (Mapvalues(false))
{
e.Canceled = true; //Prevent to execute pagging functionality
}
}