New-UDTextbox Help

Hello All

I am trying to get the value from a New-UDtextbox that is on a Show-UDModal with

New-UDtextbox -id ‘textbox’ -Label “Enter Username”

via the -onclick option on a New-UDButton with

$usrname = (Get-UDElement -Id ‘textbox’) .value
Show-UDToast -Message $usrname

but I am getting the error “cannot index into a null array”

Any help is apricated i am using version 2.9

try this:

New-UDtextbox -id "Test_Textbox" -Label "Enter Username"
new-udbutton -Text "Test Button" -OnClick {
    $usrname = (get-udelement -id "Test_Textbox").attributes.value
    Show-UDToast -Message "Username: $usrname"

thanks for the quick reply but I am still getting the same error message, any other suggestions, thanks

New-UDTextbox -Id “test” -Placeholder “Enter UserName” -Type text

$Session:usr = (Get-UDElement -Id “test”).Attributes[‘value’]

FYI the code I posted was on an endpoint page and tested working on v2.9.0

Hopefully wsl’s method works for you!

Out of interest, as I didn’t try in a modal, if you take the same code and stick it on a page directly does it work? (Rather than inside a modal)

Thanks all for your help,

First of all it was the

$usrname = (get-udelement -id “Test_Textbox”).attributes.value

that got me the textbox value, but what was stopping me in the first place was me being a complete kn08 :see_no_evil: :see_no_evil: and putting in the hide-udmodal before I got the information from the textbox, no wonder it was null, thanks all for the time and effort, Sorry I was doing something stupid.