is there a cleaner way to code this

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?cm9kY2hhcg==?=

    is there a cleaner way to code this

    hey all,

    please reference: http://pastebin.com/mef78b3d

    As shown in the reference I am dynamically building my controls in my class.
    I'd like to be able to attach javascript calls as attributes to each of my
    controls if applies.

    for example,
    String varString = "alert('i'm a textbox')";
    txt.attributes. add("onmouseove r", varString);

    now i know i can code this in each case statement but i was wondering if
    there was a way to code this once and after the switch statement and do it on
    whatever control is built?

    thanks,
    rodchar


  • Peter Duniho

    #2
    Re: is there a cleaner way to code this

    On Fri, 08 Aug 2008 08:05:01 -0700, rodchar
    <rodchar@discus sions.microsoft .comwrote:
    hey all,
    >
    please reference: http://pastebin.com/mef78b3d
    Please do not reference external web sites. Please _do_ post your code
    with your message. Please _do_ make sure your code is a
    concise-but-complete code sample. And please _do_ write a "Subject:"
    field that is reasonably descriptive of the actual question at hand.
    As shown in the reference I am dynamically building my controls in my
    class.
    I'd like to be able to attach javascript calls as attributes to each of
    my
    controls if applies.
    Does this mean you're writing a web application (i.e. using the Web.UI
    namespace)? If so, you should be specific about that, as that's
    definitely a "special case".
    for example,
    String varString = "alert('i'm a textbox')";
    txt.attributes. add("onmouseove r", varString);
    >
    now i know i can code this in each case statement but i was wondering if
    there was a way to code this once and after the switch statement and do
    it on
    whatever control is built?
    How does a switch/case statement come into it? Wouldn't it just be an
    explicit part of the initialization of the original control?

    Pete

    Comment

    • oogity

      #3
      Re: is there a cleaner way to code this

      sounds like somebody forgot her midol today


      "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
      news:op.ufks0ws i8jd0ej@petes-computer.local. ..
      On Fri, 08 Aug 2008 08:05:01 -0700, rodchar
      <rodchar@discus sions.microsoft .comwrote:
      >
      >hey all,
      >>
      >please reference: http://pastebin.com/mef78b3d
      >
      Please do not reference external web sites. Please _do_ post your code
      with your message. Please _do_ make sure your code is a
      concise-but-complete code sample. And please _do_ write a "Subject:"
      field that is reasonably descriptive of the actual question at hand.
      >
      >As shown in the reference I am dynamically building my controls in my
      >class.
      >I'd like to be able to attach javascript calls as attributes to each of
      >my
      >controls if applies.
      >
      Does this mean you're writing a web application (i.e. using the Web.UI
      namespace)? If so, you should be specific about that, as that's
      definitely a "special case".
      >
      >for example,
      >String varString = "alert('i'm a textbox')";
      >txt.attributes .add("onmouseov er", varString);
      >>
      >now i know i can code this in each case statement but i was wondering if
      >there was a way to code this once and after the switch statement and do
      >it on
      >whatever control is built?
      >
      How does a switch/case statement come into it? Wouldn't it just be an
      explicit part of the initialization of the original control?
      >
      Pete

      Comment

      • Jeroen Mostert

        #4
        Re: is there a cleaner way to code this

        oogity wrote:
        sounds like somebody forgot her midol today
        >
        It's time for another Good Idea, Bad Idea.

        Good Idea: making it easy and attractive for people to help you.
        Bad Idea: insulting people who are willing to help you for criticizing.

        --
        J.

        Comment

        • =?Utf-8?B?cm9kY2hhcg==?=

          #5
          Re: is there a cleaner way to code this

          Yes, this is a web application. This code appears in my class that implements
          ITemplate (InstantiateIn method) which is then loaded into my FormView
          dynamically.

          "Peter Duniho" wrote:
          On Fri, 08 Aug 2008 08:05:01 -0700, rodchar
          <rodchar@discus sions.microsoft .comwrote:
          >
          hey all,

          please reference: http://pastebin.com/mef78b3d
          >
          Please do not reference external web sites. Please _do_ post your code
          with your message. Please _do_ make sure your code is a
          concise-but-complete code sample. And please _do_ write a "Subject:"
          field that is reasonably descriptive of the actual question at hand.
          >
          As shown in the reference I am dynamically building my controls in my
          class.
          I'd like to be able to attach javascript calls as attributes to each of
          my
          controls if applies.
          >
          Does this mean you're writing a web application (i.e. using the Web.UI
          namespace)? If so, you should be specific about that, as that's
          definitely a "special case".
          >
          for example,
          String varString = "alert('i'm a textbox')";
          txt.attributes. add("onmouseove r", varString);

          now i know i can code this in each case statement but i was wondering if
          there was a way to code this once and after the switch statement and do
          it on
          whatever control is built?
          >
          How does a switch/case statement come into it? Wouldn't it just be an
          explicit part of the initialization of the original control?
          >
          Pete
          >

          Comment

          • Ben Voigt [C++ MVP]

            #6
            Re: is there a cleaner way to code this

            Bad Idea : discouraging people from seeking help by displaying an
            overly critical & condescending attitude.
            Peter's post wasn't condescending. He offered constructive advice on how to
            get more people to help.

            For example, because OE's support for external links is broken on my
            workstation, I haven't checked the code in question.

            If rodchar took Peter's advice he'd get more help.
            >
            Bad Idea : clog the newgroups with useless bandwith wasting
            netiquette / 'in my ng you do things my way' posts
            There was nothing possessive, just solid information on "Hhow to post a
            question that gets answered".


            Comment

            • Peter Duniho

              #7
              Re: is there a cleaner way to code this

              On Fri, 08 Aug 2008 11:47:31 -0700, oogity <boogity@newsgr oup.nospam>
              wrote:
              insulting ? it was just a comment critiquing a crappy attitude - I fail
              to
              see how being helpful ( if indeed one is being helpful ) necessitates or
              validates being needlesly critical.
              Define "needlessly critical". Personally, I find a person who posts a
              reply to a thread in which they are otherwise uninvolved, just to post an
              arbitrarily sarcastic and insulting message, to be "needlessly critical".
              Does that description sound familiar to you?

              On the other hand, nothing in _my_ post was critical at all. Every
              suggestion was phrased as a polite request, with the intent of providing
              "rodchar" with enough information for him to rephrase his question in a
              way that would be most likely to solicit useful information.

              Given that "rodchar" is a regular around here, I assumed that he didn't
              need any more sugar-coating than that just to get the idea (in fact, he
              probably needed less, but being polite is always a good idea). But even
              as it was, there was no criticism.
              [...]
              sorry for wasting anyones bandwidth with this post.
              Apology accepted.

              Pete

              Comment

              • =?Utf-8?B?cm9kY2hhcg==?=

                #8
                Re: is there a cleaner way to code this

                hey all,
                sorry for the trouble...can someone please see my previous post in response
                to Peter. did i supply enough information for additional help?

                please advise,
                rod.

                "rodchar" wrote:
                Yes, this is a web application. This code appears in my class that implements
                ITemplate (InstantiateIn method) which is then loaded into my FormView
                dynamically.
                >
                "Peter Duniho" wrote:
                >
                On Fri, 08 Aug 2008 08:05:01 -0700, rodchar
                <rodchar@discus sions.microsoft .comwrote:
                hey all,
                >
                please reference: http://pastebin.com/mef78b3d
                Please do not reference external web sites. Please _do_ post your code
                with your message. Please _do_ make sure your code is a
                concise-but-complete code sample. And please _do_ write a "Subject:"
                field that is reasonably descriptive of the actual question at hand.
                As shown in the reference I am dynamically building my controls in my
                class.
                I'd like to be able to attach javascript calls as attributes to each of
                my
                controls if applies.
                Does this mean you're writing a web application (i.e. using the Web.UI
                namespace)? If so, you should be specific about that, as that's
                definitely a "special case".
                for example,
                String varString = "alert('i'm a textbox')";
                txt.attributes. add("onmouseove r", varString);
                >
                now i know i can code this in each case statement but i was wondering if
                there was a way to code this once and after the switch statement and do
                it on
                whatever control is built?
                How does a switch/case statement come into it? Wouldn't it just be an
                explicit part of the initialization of the original control?

                Pete

                Comment

                • Marc Gravell

                  #9
                  Re: is there a cleaner way to code this

                  It sounds like you just want something like:

                  WebControl cont;
                  switch(somethin g) {
                  case 1:
                  SpecificControl spec = new SpecificControl ();
                  spec.SpecificPr operty = "blah";
                  // etc
                  cont = spec;
                  break;
                  case 2:
                  // etc;
                  cont = spec;
                  break;
                  }
                  cont.SomeBasePr operty = "foo";
                  cont.SetSomethi ng("bar");

                  ?

                  Marc

                  Comment

                  • =?Utf-8?B?cm9kY2hhcg==?=

                    #10
                    Re: is there a cleaner way to code this

                    Thanks everyone for the help,
                    rod.

                    "Marc Gravell" wrote:
                    It sounds like you just want something like:
                    >
                    WebControl cont;
                    switch(somethin g) {
                    case 1:
                    SpecificControl spec = new SpecificControl ();
                    spec.SpecificPr operty = "blah";
                    // etc
                    cont = spec;
                    break;
                    case 2:
                    // etc;
                    cont = spec;
                    break;
                    }
                    cont.SomeBasePr operty = "foo";
                    cont.SetSomethi ng("bar");
                    >
                    ?
                    >
                    Marc
                    >

                    Comment

                    Working...