How to access a methodB variable value from methodA
I have 开发者_如何转开发2 button events. When I click button1
, I am calling (by passing some values) methodA
where I am dynamically creating an array of checkboxes and an array.
Now if I click button2
, I should be able to get the values which I have set while clicking button1
(checkbox array and array values). How can I do this?
Create an object to store your values. Store the values in the ViewState
.
Make that as global variable for class.
Declare those in class scope
Maybe you could store your array into Session
or maybe the ViewState
in first button click.Retrieve the same in the other button click
Store the values in ViewState
from function1, you could retrieve that value from function B, for example,
Session["myData"] = "Hello World";///storing in session
string str = (string)Session["myData"];///retrieving from session
Use
ViewState["variable"] = [Object]
精彩评论