Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Accessing variables from the code behind page

Accessing variables from the code behind page

Scheduled Pinned Locked Moved C#
adobehardwarehelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jaimecavazos
    wrote on last edited by
    #1

    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

    H 1 Reply Last reply
    0
    • J jaimecavazos

      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

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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-----

      J 1 Reply Last reply
      0
      • H Heath Stewart

        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-----

        J Offline
        J Offline
        jaimecavazos
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups