0

I have a repeater with asp textbox and asp buttons. The user will enter a value to the textbox and click the button to process. OnClick event (let say rptrButton), I will validate the textbox value and if that value needs additional validation i will show a modal with another asp button (let say button2). My issue is sometimes I'm losing the info that i have assigned to button2 via command argument. What could be the issue? Here's a sample of my logic in the program.

rptrButton click event here's how i'm assigning a value to button2 command argument. So i wrap the button with If condition to make sure that i have the info. And if not i know that i was not able to save the info to the button. So the exception here never got thrown so it means that the info was always succesfully assigned, right?

If Not String.IsNullOrEmpty(value) Then
  button2.CommandArgument = value
Else
  Throw New Exception
End

button2 command event but here there times that this exception get thrown. Somehow on postback (onclick button2) i'm losing the value in button2 command argument. At first I'm getting the info from CommandEventArgs but same error so i changed it to button but still losing the value.

Protected Sub button2_Command(sender As Object, e As CommandEventArgs) Handles button2.Command
  Dim btn As Button = CType(sender, Button)
  If Not String.IsNullOrEmpty(btn.CommandArgument) Then
   //process
  
  Else
    Throw New Exception
  End If
End Sub
sd4ksb
  • 241
  • 1
  • 4
  • 16
  • is button2 inside the repeater, and does the repeater have more then one row of repeating data? I mean, you reference button2, but which instance of button2 inside of the repeater would it operate on? You would have to in theory using find control of the repeater item, get the button2 out of that repeater data row, and then set the value. of commandArgument. Now if button2 is outside of the repeater, then fine. but if button2 is inside of repeater, then in theory you could have 2 or 20 instances of that button - so you need to get the repeater data row (item) first. – Albert D. Kallal Sep 04 '21 at 19:30
  • The modal which has the button2 is not inside the repeater. When user clicks button1 (which is inside the repeater), on the OnClick event (server-side) is when i will assign the values for command arguments for Button2 (which is on the modal) and upon page load this modal will be shown. This logic works most of the time, we just have some occurrence of this issue once in a while. – sd4ksb Nov 29 '21 at 20:27

0 Answers0