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. Accessing input values across user controls

Accessing input values across user controls

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netwinformssysadminhelp
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.
  • G Offline
    G Offline
    GregStevens
    wrote on last edited by
    #1

    I have an ASP.NET page with a form that contains two user controls:

    <%@ Register TagPrefix="x" TagName="c1" Src="ctl1.ascx" %>
    <%@ Register TagPrefix="x" TagName="c2" Src="ctl2.ascx" %>
    <body>
      <form runat="Server">
        <x:c1 id="con1" runat="Server">
        <x:c2 id="con2" runat="Server">
      <form>
    </body>
    

    In one control (con1) I have a dropdownlist. In the other control (con2), I have a set of textboxes that I would like to pre-populate with values that depend on what item is selected in the dropdownlist in the first control. How can the code for con2 access the value of the dropdownlist in con1? Thanks for any help or suggestions. -----G

    A 1 Reply Last reply
    0
    • G GregStevens

      I have an ASP.NET page with a form that contains two user controls:

      <%@ Register TagPrefix="x" TagName="c1" Src="ctl1.ascx" %>
      <%@ Register TagPrefix="x" TagName="c2" Src="ctl2.ascx" %>
      <body>
        <form runat="Server">
          <x:c1 id="con1" runat="Server">
          <x:c2 id="con2" runat="Server">
        <form>
      </body>
      

      In one control (con1) I have a dropdownlist. In the other control (con2), I have a set of textboxes that I would like to pre-populate with values that depend on what item is selected in the dropdownlist in the first control. How can the code for con2 access the value of the dropdownlist in con1? Thanks for any help or suggestions. -----G

      A Offline
      A Offline
      Abolfazl Sheikhloo
      wrote on last edited by
      #2

      u must public the dropdownlist for your form and use it. for example: public DropDownList drop1 { get{return yourdropdownlistid;} } and use con1.drop1.SelectedItem in your form code -------------------------------------------------------- or define a dropdownlist in con2 for example: private DropDownList DropDownList1; public DropDownList con1dropdownList { get{return this.DropDownList1;} set{DropDownList1 = value;} } and in form use from: con2.con1dropdownList = con1.drop1; We Can Do Anything, If We Want It

      G 1 Reply Last reply
      0
      • A Abolfazl Sheikhloo

        u must public the dropdownlist for your form and use it. for example: public DropDownList drop1 { get{return yourdropdownlistid;} } and use con1.drop1.SelectedItem in your form code -------------------------------------------------------- or define a dropdownlist in con2 for example: private DropDownList DropDownList1; public DropDownList con1dropdownList { get{return this.DropDownList1;} set{DropDownList1 = value;} } and in form use from: con2.con1dropdownList = con1.drop1; We Can Do Anything, If We Want It

        G Offline
        G Offline
        GregStevens
        wrote on last edited by
        #3

        Well, that isn't right, because the crux of the problem is I'm working within the code-behind page of a user control, not the main page. As a result, I don't have direct accss to con2 or con1 as properties. So I can't use, for example "con1.drop1.SelectedItem", because it will say "con1 not defined". And if I try something like "Page.con1.drop1.SelectedItem" it will say that con1 is not a property of Page. I actually found my answer, though, just FYI: I needed to use the Page.FindControl() method, which solved my problem.

        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