Click to See Complete Forum and Search --> : From a UserControl to another


TheEagle
June 28th, 2007, 09:43 AM
Hi..

Metakeywords is a simple property I defined in the default page to get a member value:
string metakey; .Its code as following:



public string Metakeywords

{

get{return metakey;

}

set

{

ViewState["metakey"]=value;

metakey=(string)ViewState["metakey"];

}

}


I have used the viewstate trying to solve the problem but it doesn't make any different.
This property exist in three places:

1-default page.
2-a usercontrol(I called it welcome) in the default page.
3-a usercontrol which is loaded dynamically (in code behind) into the welcome usercontrol using the code:

contentList.Controls.Add(Page.LoadControl("UserControls/FieldContentsList.ascx"));
FieldContentsList fieldus=(FieldContentsList)contentList.Controls[0];
this.Metakeywords=fieldus.Metakeywords;

The problem is:I want to set the property in the (3-) usercontrol and get the value in the (1-)default page.

Could any one help me to solve this problem.

wmain
June 29th, 2007, 04:11 PM
I believe that the page and the user control each have their own viewstate. I would use the asp.net cache or a session variable instread. Using the cache you can set a time span for which the data is valid. Upon expiration, the item is automatically purged from the cache, freeing up the memory used by the cached object. The Session variable, on the other hand, would exist until the user logs off of the application or you set the session variable to null.

TheEagle
July 1st, 2007, 02:54 PM
Thank you for your respond but the 2 usercontrols are on the same page so I think there must be a way to get the third usercontrol property value to the page member(string metakey).We are always using Session and cache when saving values through pages(from page to another).