user control - passing values

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Re: user control - passing values

    You could declare your the controls inside your user control as public
    instead of the default of protected.
    Then you can access them directly from your web form like this:
    MyControl.MyDropdown.ToString...

    But rather than unprotecting your controls you might want to take a more
    object oriented approach and make special methods on your user control to
    expose specific control values to the page.

    For example, if you have a public method in your user control like this:
    Public Function MyDropDownListValue() as String
    Return MyDropDownList.ToString
    End Function

    Then you can call the method from your main page like this:
    MyControl.MyDropDownListValue

    --
    I hope this helps,
    Steve C. Orr, MCSD
    [url]http://Steve.Orr.net[/url]



    "Sabre" <maximNOSPAM@wave.co.nz> wrote in message
    news:OC5Srv$RDHA.3144@tk2msftngp13.phx.gbl...
    > Hello All
    >
    > I've got a form with one user control embedded. Both contain textboxes,
    > dropdownlists and checkboxes. Short of using sessions (haven't tried
    > viewstate) what means can be used to pass values between? So if checkbox1
    is
    > checked on the form, I'd like the user control to recognise this.
    Similarly
    > if a textbox on my user control contains text, I'd like to use this text
    in
    > my form.
    >
    > TIA
    > Graeme
    >
    >

    Steve C. Orr, MCSD Guest

  2. Similar Questions and Discussions

    1. How to access values of constituent controls in a User Control
      Hi All, I am building what I thought was a very simple user control in ASP.NET. The control is just a standard asp.net calendar control and a...
    2. Passing values to a custom control
      I am building a custom composite control which reads in information from an XML file. I want to be able to point my control at different XML files...
    3. Passing values from a web user control using a class - ???
      Hi. I have a web form that contains a custom user control. This control is a questionnaire with 20 questions that contains multiple radio buttons,...
    4. Passing values in User control
      You can create public properties of any data type in the user control (which is a class, after all), and then set them from the page which uses the...
    5. passing values to custom user control from dropdownlist
      i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user...
  3. #2

    Default Re: user control - passing values

    Thanks Steve. You certainly got all the answers! Regards, Graeme
    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
    news:uIErZXASDHA.2252@TK2MSFTNGP12.phx.gbl...
    > You could declare your the controls inside your user control as public
    > instead of the default of protected.
    > Then you can access them directly from your web form like this:
    > MyControl.MyDropdown.ToString...
    >
    > But rather than unprotecting your controls you might want to take a more
    > object oriented approach and make special methods on your user control to
    > expose specific control values to the page.
    >
    > For example, if you have a public method in your user control like this:
    > Public Function MyDropDownListValue() as String
    > Return MyDropDownList.ToString
    > End Function
    >
    > Then you can call the method from your main page like this:
    > MyControl.MyDropDownListValue
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD
    > [url]http://Steve.Orr.net[/url]
    >
    >
    >
    > "Sabre" <maximNOSPAM@wave.co.nz> wrote in message
    > news:OC5Srv$RDHA.3144@tk2msftngp13.phx.gbl...
    > > Hello All
    > >
    > > I've got a form with one user control embedded. Both contain textboxes,
    > > dropdownlists and checkboxes. Short of using sessions (haven't tried
    > > viewstate) what means can be used to pass values between? So if
    checkbox1
    > is
    > > checked on the form, I'd like the user control to recognise this.
    > Similarly
    > > if a textbox on my user control contains text, I'd like to use this text
    > in
    > > my form.
    > >
    > > TIA
    > > Graeme
    > >
    > >
    >
    >

    Sabre Guest

  4. #3

    Default Re: user control - passing values

    OK Steve. I've taken the easy route and declared controls as Public Shared
    WithEvents within the user control and then referenced them from aspx form
    like so:

    WebUserControl1.DropDownList4.SelectedIndex =
    WebUserControl1.DropDownList4.Items.IndexOf(WebUse rControl1.DropDownList4.It
    ems.FindByText(Session("ID")))

    That eliminated the errors ... now to overcome the "Event handler must be
    shared because its WithEvents var is shared" in the ascx page it appears I
    need to change the associated event to Public Shared like so:

    Public Shared Sub DropDownList4_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    DropDownList3.SelectedIndexChanged

    This seems fine too, but now I get the error "cannot refer to an instance
    member of class within a shared method or shared member initializer without
    an explicit instance of class" with all subs; sessions etc within the
    procedure eg:
    Button6_Click(sender, e) within the proc now errs.

    I've tried a few things, but so far, to no avail. Can you or anyone else
    help further?

    Thanks again
    Graeme



    "Steve C. Orr, MCSD" <Steve@Orr.net> wrote in message
    news:uIErZXASDHA.2252@TK2MSFTNGP12.phx.gbl...
    > You could declare your the controls inside your user control as public
    > instead of the default of protected.
    > Then you can access them directly from your web form like this:
    > MyControl.MyDropdown.ToString...
    >
    > But rather than unprotecting your controls you might want to take a more
    > object oriented approach and make special methods on your user control to
    > expose specific control values to the page.
    >
    > For example, if you have a public method in your user control like this:
    > Public Function MyDropDownListValue() as String
    > Return MyDropDownList.ToString
    > End Function
    >
    > Then you can call the method from your main page like this:
    > MyControl.MyDropDownListValue
    >
    > --
    > I hope this helps,
    > Steve C. Orr, MCSD
    > [url]http://Steve.Orr.net[/url]
    >
    >
    >
    > "Sabre" <maximNOSPAM@wave.co.nz> wrote in message
    > news:OC5Srv$RDHA.3144@tk2msftngp13.phx.gbl...
    > > Hello All
    > >
    > > I've got a form with one user control embedded. Both contain textboxes,
    > > dropdownlists and checkboxes. Short of using sessions (haven't tried
    > > viewstate) what means can be used to pass values between? So if
    checkbox1
    > is
    > > checked on the form, I'd like the user control to recognise this.
    > Similarly
    > > if a textbox on my user control contains text, I'd like to use this text
    > in
    > > my form.
    > >
    > > TIA
    > > Graeme
    > >
    > >
    >
    >

    Sabre Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139