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
  1. Home
  2. Web Development
  3. ASP.NET
  4. HELP! Accessing controls on a user control

HELP! Accessing controls on a user control

Scheduled Pinned Locked Moved ASP.NET
questioncsharpvisual-studiowinformshelp
4 Posts 3 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.
  • I Offline
    I Offline
    Infernojericho
    wrote on last edited by
    #1

    Hi, I have a rather stupid question, hope someone can help me. I am writing a webpage in C#, in VS.NET 2003. To make things easier I used some user controls. However, my question how can I access the controls in the webpage. Let's say I have my aspx page A, and user control B that is within the aspx page A. I have a textbox in the User control B. And I want to pass the value of the textbox to another page from a Button in Aspx page A. The regular approach of Session["textboxvar"]=TextboxB.Text simply doesn't work. VS.NET 2003 is complaining "The type or namespace name 'TextboxB' could not be found." How can I access it? Many, many thanks!!!

    C 1 Reply Last reply
    0
    • I Infernojericho

      Hi, I have a rather stupid question, hope someone can help me. I am writing a webpage in C#, in VS.NET 2003. To make things easier I used some user controls. However, my question how can I access the controls in the webpage. Let's say I have my aspx page A, and user control B that is within the aspx page A. I have a textbox in the User control B. And I want to pass the value of the textbox to another page from a Button in Aspx page A. The regular approach of Session["textboxvar"]=TextboxB.Text simply doesn't work. VS.NET 2003 is complaining "The type or namespace name 'TextboxB' could not be found." How can I access it? Many, many thanks!!!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      First of all, don't use the session if you can avoid it. You have user controls. You can put two controls on the same page, and switch which one is visible, and then viewstate will hold the values for you. you can also pass values on the URL. TextboxB exists in the user control, so that's where you need to write the code to interact with it. You can also use delegates to get your user controls to call code in other controls or the main page.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      L 1 Reply Last reply
      0
      • C Christian Graus

        First of all, don't use the session if you can avoid it. You have user controls. You can put two controls on the same page, and switch which one is visible, and then viewstate will hold the values for you. you can also pass values on the URL. TextboxB exists in the user control, so that's where you need to write the code to interact with it. You can also use delegates to get your user controls to call code in other controls or the main page.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        L Offline
        L Offline
        lovedotnet
        wrote on last edited by
        #3

        a simple solution is write a public method in user control which returns the textbox value like public string GettbValue(){ return this.Textbox.Text;} and access this method in ur aspx page by using B.GettbValue() method and send it using querystring... i hope this will help you thanks, deep. :)

        C 1 Reply Last reply
        0
        • L lovedotnet

          a simple solution is write a public method in user control which returns the textbox value like public string GettbValue(){ return this.Textbox.Text;} and access this method in ur aspx page by using B.GettbValue() method and send it using querystring... i hope this will help you thanks, deep. :)

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          May as well make this a property.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          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