Accessing variables from the code behind page
-
I'm trying to pass variables from my main.aspx page to the web user control page. I have a flash application that reads the variables and based on that displays a certain item that's embedded in the web user control page. The variable that I created needs to be on the main.aspx page, so when flash opens up it can tell which page it's on. It looks something like this: This is on the control.ascx page, the problem with this is that it has to be on the same aspx page. This is on the main.aspx.cs page public string pageStatus() { return "home"; } I have also accomplished my goal by using session variables, but I don't want to use them. Is there is any way to inheret the function that's on the main.aspx or pass somekind of global variable to where it can be accessed anywhere. Remember that the variable needs to be in the main.aspx page, it can't be in a class library or component. Thanks, Jaime C
-
I'm trying to pass variables from my main.aspx page to the web user control page. I have a flash application that reads the variables and based on that displays a certain item that's embedded in the web user control page. The variable that I created needs to be on the main.aspx page, so when flash opens up it can tell which page it's on. It looks something like this: This is on the control.ascx page, the problem with this is that it has to be on the same aspx page. This is on the main.aspx.cs page public string pageStatus() { return "home"; } I have also accomplished my goal by using session variables, but I don't want to use them. Is there is any way to inheret the function that's on the main.aspx or pass somekind of global variable to where it can be accessed anywhere. Remember that the variable needs to be in the main.aspx page, it can't be in a class library or component. Thanks, Jaime C
Do a Type-check and cast it. From the UserControl:
private void Page_Load(object sender, EventArgs e)
{
string value = null;
if (Page is main) // Where "main" is the Type for main.aspx.cs class
value = ((main)Page).pageStatus();
}-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
Do a Type-check and cast it. From the UserControl:
private void Page_Load(object sender, EventArgs e)
{
string value = null;
if (Page is main) // Where "main" is the Type for main.aspx.cs class
value = ((main)Page).pageStatus();
}-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Hey Heath, The function that I created on the main.aspx.cs page can be accessed from user.ascx.cs page, I don't have any problem with that. In traditional .asp pages I could just create a variable called pageStatus = "main" on the main.asp page and the user.ascs page would be an include file which would hold my flash application that have status = <%pageStatus%>, so if I went to home.asp page, the home.asp page would have pageStatus="home" and the services.asp page would have pageStatus="services". So in my flash application anytime you would go a page it would display the value of that page accordingly. Sorry, if I sound frustrated, doing some of the simpliest things in asp is a little more difficult in asp.net. I wrote this function out of frustration, I know there is a simpler way to do it. Thanks a lot in advance! public string pageStatus() { string strURL = Request.ServerVariables["URL"]; StringBuilder replaceFunc = new StringBuilder(strURL); strURL = replaceFunc.Replace("/web_isotope/","").ToString(); strURL = replaceFunc.Replace(".aspx","").ToString(); return strURL; } Also can I inheret the class from my main.aspx.cs page in the user.ascs.cs page. Thanks again. Jaime