Passing 'this' to a function

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

  1. #1

    Default Passing 'this' to a function

    I would like to create a class that changes some basic
    attributes of a web page based on values in a database.
    Things like background color, font, text color, etc. My
    problem is that I'm not sure how to pass the
    variable 'this' to a class function. I need to be able
    modify the properties of the controls on the web page.

    Has anyone done something like this?

    Thanks for the help!
    Gary
    Gary Monk Guest

  2. Similar Questions and Discussions

    1. Passing a ROWTYPE to a function
      I'm trying to write a function that takes a %ROWTYPE as an argument. I'm just not sure how to call it from another function. This is what I tried:...
    2. Passing db values to function
      Hello, I am creating dynamic images with corresponding checkboxes by pulling data from an Access database. The onchange event of the checkboxes...
    3. passing a function as a ref?
      can you pass a reference to a function, then call it? How do I do it? The following does not work: function aaa(myFunc){ eval(myFunc); }...
    4. Passing a variable to a package function vs. a local function
      I'm a bit new to this so please bear with me... I've written a script that uses CGI.pm something like this: use CGI::Carp qw(fatalsToBrowser);...
    5. Passing a hash to a function
      I can't seem to find in in my perl book. I'd like to pass hashes to functions #!/usr/bin/perl -wT my %someHash; $someHash{'one'} = "1";...
  3. #2

    Default Re: Passing 'this' to a function

    I believe your problem lies in the fact that your function defines the
    parameter type as a reference to the Base Page class, rather than a
    reference to your inherited Page class. The types don't match exactly.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "Gary Monk" <g_monk@hotmail.com> wrote in message
    news:024601c35156$f8772120$a401280a@phx.gbl...
    > Kevin,
    >
    > Thanks for the reply.
    >
    > I'm receiving the following error...
    >
    > C:\inetpub\wwwroot\MYOWorks\schedule.aspx.cs(114): The
    > best overloaded method match
    > for 'MYOWorks.MYOPage.SetPageDefaults(ref
    > System.Web.UI.Page)' has some invalid arguments
    >
    > I didn't mention in my first post I'm using C#. I'm not
    > sure if this makes a difference in the coding example.
    >
    > Here is the code I'm using...
    >
    > In the class...
    >
    > public void SetPageDefaults(ref System.Web.UI.Page
    > objPage)
    > {
    > .
    > .
    > .
    >
    > In the program...
    >
    > pageSetup.SetPageDefaults( ref this );
    >
    > Thanks,
    > Gary
    >
    > >-----Original Message-----
    > >In your class:
    > >
    > >private function doWithThis(ref System.Web.UI.Page
    > objPage)
    > >{
    > >// do something with the Page
    > >}
    > >
    > >In your page:
    > >
    > >ClassName.doWithThis(ref this);
    > >
    > >--
    > >HTH,
    > >
    > >Kevin Spencer
    > >Microsoft MVP
    > >..Net Developer
    > >[url]http://www.takempis.com[/url]
    > >Big things are made up of
    > >lots of little things.
    > >
    > >"Gary Monk" <g_monk@hotmail.com> wrote in message
    > >news:02f201c35146$c2dfbff0$a001280a@phx.gbl...
    > >> I would like to create a class that changes some basic
    > >> attributes of a web page based on values in a database.
    > >> Things like background color, font, text color, etc. My
    > >> problem is that I'm not sure how to pass the
    > >> variable 'this' to a class function. I need to be able
    > >> modify the properties of the controls on the web page.
    > >>
    > >> Has anyone done something like this?
    > >>
    > >> Thanks for the help!
    > >> Gary
    > >
    > >
    > >.
    > >

    Kevin Spencer Guest

  4. #3

    Default Re: Passing 'this' to a function

    Oops. I said "her." Sorry, Gary!

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    ..Net Developer
    [url]http://www.takempis.com[/url]
    Big things are made up of
    lots of little things.

    "Kevin Spencer" <kevin@takempis.com> wrote in message
    news:Obl0$rVUDHA.2180@TK2MSFTNGP12.phx.gbl...
    > Well, yes and no. It is a reference, and you can pass it to a function and
    > make changes to the data contained therein, but not the reference itself.
    In
    > her case, it really wouldn't make any difference, since she only wants to
    > make changes to the properties of the page.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > .Net Developer
    > [url]http://www.takempis.com[/url]
    > Big things are made up of
    > lots of little things.
    >
    > "szabelin" <szabelin@szabelin> wrote in message
    > news:03e201c35156$1fd5d2d0$a301280a@phx.gbl...
    > >
    > > Kevin, I was just curios why pass objPage by ref? Isn't
    > > objPage already a reference?
    > >
    > > Thanks
    > >
    > >
    > > >-----Original Message-----
    > > >In your class:
    > > >
    > > >private function doWithThis(ref System.Web.UI.Page
    > > objPage)
    > > >{
    > > >// do something with the Page
    > > >}
    > > >
    > > >In your page:
    > > >
    > > >ClassName.doWithThis(ref this);
    > > >
    > > >--
    > > >HTH,
    > > >
    > > >Kevin Spencer
    > > >Microsoft MVP
    > > >..Net Developer
    > > >[url]http://www.takempis.com[/url]
    > > >Big things are made up of
    > > >lots of little things.
    > > >
    > > >"Gary Monk" <g_monk@hotmail.com> wrote in message
    > > >news:02f201c35146$c2dfbff0$a001280a@phx.gbl...
    > > >> I would like to create a class that changes some basic
    > > >> attributes of a web page based on values in a database.
    > > >> Things like background color, font, text color, etc. My
    > > >> problem is that I'm not sure how to pass the
    > > >> variable 'this' to a class function. I need to be able
    > > >> modify the properties of the controls on the web page.
    > > >>
    > > >> Has anyone done something like this?
    > > >>
    > > >> Thanks for the help!
    > > >> Gary
    > > >
    > > >
    > > >.
    > > >
    >
    >

    Kevin Spencer Guest

  5. #4

    Default Re: Passing 'this' to a function

    No problem. Thanks for the help!!!

    Gary
    >-----Original Message-----
    >Oops. I said "her." Sorry, Gary!
    >
    >--
    >HTH,
    >
    >Kevin Spencer
    >Microsoft MVP
    >..Net Developer
    >[url]http://www.takempis.com[/url]
    >Big things are made up of
    >lots of little things.
    >
    >"Kevin Spencer" <kevin@takempis.com> wrote in message
    >news:Obl0$rVUDHA.2180@TK2MSFTNGP12.phx.gbl...
    >> Well, yes and no. It is a reference, and you can pass
    it to a function and
    >> make changes to the data contained therein, but not
    the reference itself.
    >In
    >> her case, it really wouldn't make any difference,
    since she only wants to
    >> make changes to the properties of the page.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> .Net Developer
    >> [url]http://www.takempis.com[/url]
    >> Big things are made up of
    >> lots of little things.
    >>
    >> "szabelin" <szabelin@szabelin> wrote in message
    >> news:03e201c35156$1fd5d2d0$a301280a@phx.gbl...
    >> >
    >> > Kevin, I was just curios why pass objPage by ref?
    Isn't
    >> > objPage already a reference?
    >> >
    >> > Thanks
    >> >
    >> >
    >> > >-----Original Message-----
    >> > >In your class:
    >> > >
    >> > >private function doWithThis(ref System.Web.UI.Page
    >> > objPage)
    >> > >{
    >> > >// do something with the Page
    >> > >}
    >> > >
    >> > >In your page:
    >> > >
    >> > >ClassName.doWithThis(ref this);
    >> > >
    >> > >--
    >> > >HTH,
    >> > >
    >> > >Kevin Spencer
    >> > >Microsoft MVP
    >> > >..Net Developer
    >> > >[url]http://www.takempis.com[/url]
    >> > >Big things are made up of
    >> > >lots of little things.
    >> > >
    >> > >"Gary Monk" <g_monk@hotmail.com> wrote in message
    >> > >news:02f201c35146$c2dfbff0$a001280a@phx.gbl...
    >> > >> I would like to create a class that changes some
    basic
    >> > >> attributes of a web page based on values in a
    database.
    >> > >> Things like background color, font, text color,
    etc. My
    >> > >> problem is that I'm not sure how to pass the
    >> > >> variable 'this' to a class function. I need to be
    able
    >> > >> modify the properties of the controls on the web
    page.
    >> > >>
    >> > >> Has anyone done something like this?
    >> > >>
    >> > >> Thanks for the help!
    >> > >> Gary
    >> > >
    >> > >
    >> > >.
    >> > >
    >>
    >>
    >
    >
    >.
    >
    Gary Monk 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