Hello Everyone,
Now I am tell you about viewstate. to get value of viewstate from another page using StateBag Class.
Lets example there is two page 1) First.aspx 2) Second.aspx
where we set viewstate value in First.aspx on some button click and then redirect to Second.aspx where we get value of viewstate which we set in Frist Page.
1) Button Click in First.aspx (.cs file Code)
Thank You So Much !!!!!!!!
Now I am tell you about viewstate. to get value of viewstate from another page using StateBag Class.
Lets example there is two page 1) First.aspx 2) Second.aspx
where we set viewstate value in First.aspx on some button click and then redirect to Second.aspx where we get value of viewstate which we set in Frist Page.
1) Button Click in First.aspx (.cs file Code)
protected void button_Click(object sender, EventArgs e) { // Set Viewstate Value ViewState["Name"] = "Chetan" ; Server.Transfer("Second.aspx"); }
2) Create Method of class StateBag
public StateBag ReturnViewStateValue() { return ViewState; }3) Now to get the value of viewstate in second.aspx paste following method in second.aspx page :
private StateBag FirstPageViewStateValue { get { StateBag value = null; if (PreviousPage != null) { Object objFirstPage = (Object)PreviousPage; MethodInfo objMethod = objFirstPage.GetType().GetMethod("ReturnViewStateValue"); return (StateBag)objMethod.Invoke(objFirstPage,null); } return value; } }4) Now just get the value of viewstate in second.aspx in page load method using following code :
protected void Page_Load(object sender, EventArgs e) { if (PreviousPage != null && FirstPageViewStateValue != null) { string Name = Convert.ToString(FirstPageViewStateValue["Name"]); } }Finally we get the viewstate value.
Thank You So Much !!!!!!!!
No comments:
Post a Comment