# Powershel Forms Change one button's action

**URL:** <https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420>\
**Category:** PowerShell Help\
**Created:** [April 18, 2019, 8:56am UTC](https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420 "2019-04-18T08:56:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@nad](https://forums.powershell.org/u/nad)\
**Post date:** [April 18, 2019, 8:56am UTC](https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420/1 "2019-04-18T08:56:52Z")

</div>

Good afternoon,

I’m latelly strugling with my Forms script for a specific action I’d like to do, to help understanding, I’ll show part of codes while explaining.

I have 4 button that each show the exact same thing, we will name them **ActionButton**

```
**$ButtonDL.Add\_Click** ({
$FormInformationUserWindows.controls.AddRange(@($blocmail))
$blocmail.controls.AddRange(@($labelemail,$Textboxemail,$ButtonExport,$ButtonShow)) **$ButtonExport.Add\_click** ({ 
$Data = DL
Exp})
```

In that button, another button is Added which we’ll call **Buttonexport** , uppon clicking on it, it will call a function into a variable and then another function that is a **Forms.SaveFileDialog** for saving the output of **$Data**

&nbsp;

Issue here is when I click on another of **ActionButton** , then click on **$ButtonExport** , here what happens:

1- Script will firstly execute again the first **ActionButton** clicked on at the begining

2- Then script will execute the newly clicked **ActionButton**

If I click on a 3rd **ActionButton** , it will do exactly the 2 step above then will execute the action the 3rd **ActionButton**.

I tried clearing, closing or removing and adding anew the **Buttonexport** for every click performed on the **ActionButton** but it still keep in memory the first called function.

&nbsp;

If someone have an idea of how this could be handled, that would very appreciated.

&nbsp;

Thank you

Nad

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [April 21, 2019, 10:10pm UTC](https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420/2 "2019-04-21T22:10:44Z")

</div>

You should put your code on GitHub or gist for use to see what you mean. For as you explain it, it’s not clear what use case is.  
I’d say record a gif using say, [https://www.screentogif.com](https://www.screentogif.com) (or other format) of what you say you are seeing.

If you are reusing variable names, etc., and not clearing them before reuse, even in the same session, code path, then I’d expect it to be populated from a previous run in the same session. Well, based on what you say you are doing.

---

<div class="post-metadata">

**Author:** ![nad](https://avatars.discourse-cdn.com/v4/letter/n/ed8c4c/32.png) [@nad](https://forums.powershell.org/u/nad)\
**Post date:** [April 23, 2019, 4:03am UTC](https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420/3 "2019-04-23T04:03:28Z")

</div>

I think the best way to describe what I’m looking for is how to clear a button’s value, functions, variables… when an action linked to it is done  
I tried $From.Controls.clear($Button) but it doesn’t work

From what I found, most people reset the complete form, but I’m looking for a way to avoid that

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/powershel-forms-change-one-buttons-action/12420/4 "2024-05-16T20:32:56Z")

</div>

Closed on May 16, 2024, 8:32pm UTC


