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. Web user control

Web user control

Scheduled Pinned Locked Moved ASP.NET
tutorial
11 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.
  • P Offline
    P Offline
    peepys
    wrote on last edited by
    #1

    hi, How to access a web user's control method & property that is placed on webform.aspx. Regards, aB

    M 1 Reply Last reply
    0
    • P peepys

      hi, How to access a web user's control method & property that is placed on webform.aspx. Regards, aB

      M Offline
      M Offline
      munklefish
      wrote on last edited by
      #2

      A user control block should be present on the page if using Vis studio Simply select it and use properties window.

      P 1 Reply Last reply
      0
      • M munklefish

        A user control block should be present on the page if using Vis studio Simply select it and use properties window.

        P Offline
        P Offline
        peepys
        wrote on last edited by
        #3

        Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005

        M 2 Replies Last reply
        0
        • P peepys

          Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005

          M Offline
          M Offline
          munklefish
          wrote on last edited by
          #4

          Hmm, I tried adding things to a drop list and its a lot harder than it seems. Most responses tend to be to set the values in the properties box. This doesnt always work and of course you dont have access to the properties. You could try setting them from within the actual ascx page. Otherwise you will need to do something like the following to manually populate the ddl's DropDownList5.Items.Clear(); ListItem li5 = new ListItem("",""); DropDownList5.Items.Add(li5); foreach (DataRow dr in ds.Tables["times"].Rows) { //Some code to fills rows} That should do the job.

          1 Reply Last reply
          0
          • P peepys

            Thanks, but still i'm not able to get it.:wtf: Here is what i have done: I have created a web user control (MYCTR.ascx) with DropDownList filled with names, to deploy it in default.aspx i put: <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> To add the control in default.aspx i put: "MyComp:Ctl id="MYT" runat="server/" Things are working, but i would like access an item in DropDown list, how do i do ? Regards, aB -- modified at 11:55 Sunday 11th December, 2005

            M Offline
            M Offline
            munklefish
            wrote on last edited by
            #5

            ????? What do you mean? Youre not making much sense. Sorry! Do you mean that no values / text is displayed in the drop down list?

            P 1 Reply Last reply
            0
            • M munklefish

              ????? What do you mean? Youre not making much sense. Sorry! Do you mean that no values / text is displayed in the drop down list?

              P Offline
              P Offline
              peepys
              wrote on last edited by
              #6

              ok,:doh: 1.MyCtr.ASCX contains a DDlist with 5 items. 2.Default.ASPX contains one MyButton 3.After deploying MyCtr.ASCX in default.ASPX, i want to get "DDlist.SelectedItem.Text" FROM MyButton_click() Thanks aB -- modified at 13:09 Sunday 11th December, 2005

              M 1 Reply Last reply
              0
              • P peepys

                ok,:doh: 1.MyCtr.ASCX contains a DDlist with 5 items. 2.Default.ASPX contains one MyButton 3.After deploying MyCtr.ASCX in default.ASPX, i want to get "DDlist.SelectedItem.Text" FROM MyButton_click() Thanks aB -- modified at 13:09 Sunday 11th December, 2005

                M Offline
                M Offline
                munklefish
                wrote on last edited by
                #7

                ok, string temp = DropDownList3.SelectedItem.Value; to get data from drop list. Then you need to tell MyButton_click() to return the value. So something like: return temp;

                P 1 Reply Last reply
                0
                • M munklefish

                  ok, string temp = DropDownList3.SelectedItem.Value; to get data from drop list. Then you need to tell MyButton_click() to return the value. So something like: return temp;

                  P Offline
                  P Offline
                  peepys
                  wrote on last edited by
                  #8

                  Thanks !

                  P 1 Reply Last reply
                  0
                  • P peepys

                    Thanks !

                    P Offline
                    P Offline
                    peepys
                    wrote on last edited by
                    #9

                    hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste

                    M R 2 Replies Last reply
                    0
                    • P peepys

                      hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste

                      M Offline
                      M Offline
                      munklefish
                      wrote on last edited by
                      #10

                      Hi, are their any benefits or otherwise to loading the control in this manner compared to the conventional method i described earlier? Just interested.

                      1 Reply Last reply
                      0
                      • P peepys

                        hi, i have found another way to do this: #1) By default DDlist in MYCTR.ASCX is "protected" change it "Public" #2) In default.ASPX, load the control using NewCtr=Loadcontrol("MyCTR.ascx") method #3) ... and now i can access Newctr.DDlist.selecteditem.text Actually this is what i was expecting... thanks for you great support Regards aBaste

                        R Offline
                        R Offline
                        RSArockiam
                        wrote on last edited by
                        #11

                        why are you using Loadcontrol method? This is not a good sense. Just put the definition for this control like other controls. for ex: ASPX ==== <%@ Register TagPrefix="Mycomp" TagName="ctl" Src="MYCTR.ascx" %> ... "MyComp:Ctl id="MYT" runat="server" /> CodeBehind =========== protected ctl MYT; in the control definition part. Now u can use MYT.DDlist.selecteditem.text Regards R.Arockiapathinathan

                        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