raising an event inside a user control that returns CommandEventArgs
-
08-10-2019 - |
Question
hi all i have the following problam:
i have a user control which i want to raise an event from to the page that is using that user control (its a button)
anyway my problem started when i wanted to put this user control inside a repeater instead of another button (regular asp:button) anyway i needed to support CommandArgument so that page can use the button
so i created a property:
Private m_CommandArgument As Object
Public Property CommandArgument() As Object
Get
Return m_CommandArgument
End Get
Set(ByVal Value As Object)
m_CommandArgument = Value
End Set
End Property
but... when i try to raise the event this property dosnt keep his state...
cmdEvent = New CommandEventArgs(CommandName, CommandArgument)
so after i press the button and the postback happen my raised event dosnt have a value.. where should this property be saved in order for it to have a value after postback? view state? how do i add to the the viewstate automaticly?
thanks!
Solution
ok so i figured out a way i can do this...
and its very simple like so:
Private m_CommandArgument As Object
Public Property CommandArgument() As Object
Get
'Return m_CommandArgument
Return ViewState("confirmCommandArgument")
End Get
Set(ByVal Value As Object)
ViewState("confirmCommandArgument") = Value
'm_CommandArgument =
End Set
End Property
so actualy simply saving it in the viewstate...