User Controls

Discussion in 'ASP .Net' started by =?Utf-8?B?SmltIEhlYXZleQ==?=, Jun 6, 2004.

  1. Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a Variable name of "Public string Fred" in the control, will the page that uses the control be able to see this global variable or is there something that I need to do to make it available to the page which uses the control

    Thanks in advance for your assistance!!!!
    =?Utf-8?B?SmltIEhlYXZleQ==?=, Jun 6, 2004
    #1
    1. Advertising

  2. "Jim Heavey" <> wrote in message
    news:D...
    > Hello, I have a user control which I place at the top of each page. I

    want to have code in this user control which sets the value of a couple of
    module variables and I was wondering if I create a Variable name of "Public
    string Fred" in the control, will the page that uses the control be able to
    see this global variable or is there something that I need to do to make it
    available to the page which uses the control?

    Jim, all due respect, but many of your recent questions suggest you might
    want to pick up a book on ASP.NET. In particular, one of the greatest
    advances of ASP.NET over ASP is the fact that it uses OO techniques.

    Modules are not an OO technique. You should immediately stop using them and
    start finding OO alternatives. In the .NET world, modules should be used
    only as containers of global, shared methods, and not for data at all. A
    module is nothing much more than a public class all of whose members are
    public and Shared. Using such a class instead of a module will make it much
    clearer that, for instance, all of the variable members will be shared by
    all users, ans shared without any synchronization as well.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 6, 2004
    #2
    1. Advertising

  3. Thanks for your comments

    I am sorry to say that I have a number of books on ASP.Net. I have "Professional ASP.Net 1.0" which provides little insight to how to use User Controls. It provides nothing in terms of how to use Javascript with ASP.Net controls (another of my questions)

    I think my question is a fair question. If I am going to be using a User Control and that User control has to retrieve information from the database. This information control how the page will operate. If I retrieve this information within the control, how can I provide that information to the page which contains the control. The book that I have does not discuss this issue, and I am sure I could pick up atleast 12 other books which do not as well

    If you would care to recommend a book, please do. If you care to point out how I might be able to use an OO technique for this issue, by all means do not restrain your self.
    =?Utf-8?B?SmltIEhlYXZleQ==?=, Jun 6, 2004
    #3
  4. User control can have properties that the hosting page can set and get.

    If you want it event driven, then you could make use of events that the user control raise and any interested objects i.e. the hosting pages, could 'get' the value in the user control in the form of event arg

    Hope this helps

    Good luck...
    =?Utf-8?B?c3Bhcm1hcg==?=, Jun 6, 2004
    #4
  5. Thanks..
    =?Utf-8?B?SmltIEhlYXZleQ==?=, Jun 6, 2004
    #5
  6. =?Utf-8?B?SmltIEhlYXZleQ==?=

    clintonG Guest

    The QUE MCAD Training Guides are very good as they cover
    each aspect of developing ASP.NET, controls, and XML Web Services.
    Do the exercises which cover a wide range of objective tasks. I've
    favored those for C# three of which were authored by Amit Kahlani
    who did a very good job. Finally, you'll get a lot more out of
    articles posted to the various focus group websites once you have
    a training guide that covers eask aspect of development.

    --
    <%= Clinton Gallagher
    A/E/C Consulting, Web Design, e-Commerce Software Development
    Wauwatosa, Milwaukee County, Wisconsin USA
    NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
    URL http://www.metromilwaukee.com/clintongallagher/



    "Jim Heavey" <> wrote in message
    news:...
    > Thanks for your comments.
    >
    > I am sorry to say that I have a number of books on ASP.Net. I have

    "Professional ASP.Net 1.0" which provides little insight to how to use User
    Controls. It provides nothing in terms of how to use Javascript with ASP.Net
    controls (another of my questions).
    >
    > I think my question is a fair question. If I am going to be using a User

    Control and that User control has to retrieve information from the database.
    This information control how the page will operate. If I retrieve this
    information within the control, how can I provide that information to the page
    which contains the control. The book that I have does not discuss this issue,
    and I am sure I could pick up atleast 12 other books which do not as well.
    >
    > If you would care to recommend a book, please do. If you care to point out

    how I might be able to use an OO technique for this issue, by all means do not
    restrain your self.
    clintonG, Jun 6, 2004
    #6
  7. "Jim Heavey" <> wrote in message
    news:...
    > Thanks for your comments.
    >
    > I am sorry to say that I have a number of books on ASP.Net. I have

    "Professional ASP.Net 1.0" which provides little insight to how to use User
    Controls. It provides nothing in terms of how to use Javascript with
    ASP.Net controls (another of my questions).
    >
    > I think my question is a fair question. If I am going to be using a User

    Control and that User control has to retrieve information from the database.
    This information control how the page will operate. If I retrieve this
    information within the control, how can I provide that information to the
    page which contains the control. The book that I have does not discuss this
    issue, and I am sure I could pick up atleast 12 other books which do not as
    well.
    >
    > If you would care to recommend a book, please do. If you care to point

    out how I might be able to use an OO technique for this issue, by all means
    do not restrain your self.

    Jim, sorry to reply so late, but you've received useful responses in the
    meantime.

    The basic concept is that user controls are classes. Anything you learn
    which applies to classes applies to user controls.

    In particular, you are correct that you could load the data inside of the
    user control. You could then expose the data to the outside world by adding
    a public read-only property to the user control which would expose the data.
    It could be of type DataSet, for instance.

    You could also do it the other way around. Have the "caller" of the user
    control load the data and then pass the data to the user control. Again,
    this could be done via a property, though this time, it wouldn't be
    read-only.

    Depending on the nature of the data, you might want to use a more general
    type than DataSet for the data being passed. For instance, making it of type
    IEnumerable would allow you to pass almost anything into the user control,
    which means that the data source could change without requiring the user
    control to change.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jun 7, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. trinitypete

    HTML Controls and User controls

    trinitypete, Jun 25, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    3,373
    trinitypete
    Jun 26, 2003
  2. Axel Dahmen
    Replies:
    1
    Views:
    486
    Teemu Keiski
    Nov 12, 2003
  3. Nathan Sokalski
    Replies:
    4
    Views:
    1,141
    Muhammad Naveed Yaseen
    Sep 5, 2007
  4. Faizan Ahmed
    Replies:
    1
    Views:
    281
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    357
    John Saunders
    Jan 4, 2005
Loading...

Share This Page