function samples

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Kurten

    function samples

    in the visual studio .NET samples that come with the product, why do
    javascript functions all have the parameters below. Even though, the event
    (like Onclick) which is calling it doesn't have any parameters.

    private function somename(sender :Object, e:EventArgs)

    thanks.



  • Showjumper

    #2
    Re: function samples

    I belive you are confusing a server OnClick event with a client side onclick
    event. The OnClick(s as object, e as eventargs) is for server side stuff.
    "Mark Kurten" <mark_kurten@ac ordia.com> wrote in message
    news:%23$J5D8s3 DHA.3436@tk2msf tngp13.phx.gbl. ..[color=blue]
    > in the visual studio .NET samples that come with the product, why do
    > javascript functions all have the parameters below. Even though, the[/color]
    event[color=blue]
    > (like Onclick) which is calling it doesn't have any parameters.
    >
    > private function somename(sender :Object, e:EventArgs)
    >
    > thanks.
    >
    >
    >[/color]


    Comment

    • Steven Cheng[MSFT]

      #3
      RE: function samples

      Hi Mark,


      Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
      assisting you on this issue.
      From your description, you'd like to know why there are some script
      function in the page's source file and they have some parameters declared,
      however, in the control's event attribute, the calling function don't take
      any parameter such as:
      private function somename(sender :Object, e:EventArgs)
      {
      ......
      }

      and we use this fuction for a control 's "OnClick" event like:
      <asp:Button id="btn" OnClick="somena me" />

      If there is anything I misunderstood, please feel free to let me know.

      As for this question, I think it i because the different program style of
      clientside script block and serverside code block:
      1.Generally, if we develop the ASP.NET page in VS.NET, when we create a web
      page, the IDE will help use create a code-hehind class file together with
      the page. Then, we can write the serverside event handler, such as server
      control's click even's handler in the code-behind class file(.aspx.cs or
      ..aspx.vb files). For example:
      private void Page_Load(objec t sender, System.EventArg s e) // page's click
      event handler
      {
      ............... .

      }

      private void btnPrint_Click( object sender, System.EventArg s e) // a certain
      button's click handler
      {
      ............... .

      }

      these serverside event handlers normally all take two paramteres,one
      (sender) is the source of the event, and the other (e, EventArgs or its
      derived class) contains some infos of the event. When we add the handler to
      a certain control's event's handler collection, we only need to provide the
      function's name , not argument list needed, for example:

      this.btnPrint.C lick += new System.EventHan dler(this.btnPr int_Click);
      this.Load += new System.EventHan dler(this.Page_ Load);

      However, if we don't use the code-behind page class file, then we just
      write these handler functions in the aspx file and in such code blocks as
      below:
      <script language="C#" runat="server">
      .....
      private void btnPrint_Click( object sender, System.EventArg s e) // a certain
      button's click handler
      {
      ............... .

      }
      </script>

      and we also speify the handler for a ASP.NET server control in the file
      like:
      <asp:button id="btnPrint" runat="server" Text="Print"
      OnClick="btnPri nt_Click"></asp:button>
      Just the function name, no parameter needed. Since the ASP.NET runtime will
      help you to generate the "sender" and "e" object from the control
      automaitcally.
      For more detailed info on event handler in ASP.NET serverside , you may
      view the following reference in MSDN:
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      ame=true

      #Creating Event Handlers in Web Forms Pages
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      sInWebFormsPage s.asp?frame=tru e


      2. The function I discussed in 1. is the server side code in ASP.NET. In
      addition, we can write client side script code such as javascript in the
      aspx page source file, for example:
      <script language="javas cript">
      function jsfn()
      {
      alert("hello world!");
      }

      function sayHello(name)
      {
      alert("hello world" + name);
      }
      </script>

      But be careful, such client side script is quite different from the
      serverside code, they only runat the client's browser. You can see the
      <script ..> block doesn't have "runat=serv er". And the client side script's
      function could also take paramter or doesn't take parameter. I've shown the
      two condition in the above example.
      If you need more information on clientside scripting, you may view the
      following link for reference:

      #javascript overview and examples
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      ue


      Please check out the above items to see whether they help. If you need any
      further assistance, please feel free to let me know.


      Regards,

      Steven Cheng
      Microsoft Online Support

      Get Secure! www.microsoft.com/security
      (This posting is provided "AS IS", with no warranties, and confers no
      rights.)

      Comment

      • Mark Kurten

        #4
        Re: function samples

        thank you very much for the detailed explanation...



        "Steven Cheng[MSFT]" <v-schang@online.m icrosoft.com> wrote in message
        news:C1XbEEy3DH A.3348@cpmsftng xa07.phx.gbl...[color=blue]
        > Hi Mark,
        >
        >
        > Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
        > assisting you on this issue.
        > From your description, you'd like to know why there are some script
        > function in the page's source file and they have some parameters declared,
        > however, in the control's event attribute, the calling function don't take
        > any parameter such as:
        > private function somename(sender :Object, e:EventArgs)
        > {
        > .....
        > }
        >
        > and we use this fuction for a control 's "OnClick" event like:
        > <asp:Button id="btn" OnClick="somena me" />
        >
        > If there is anything I misunderstood, please feel free to let me know.
        >
        > As for this question, I think it i because the different program style of
        > clientside script block and serverside code block:
        > 1.Generally, if we develop the ASP.NET page in VS.NET, when we create a[/color]
        web[color=blue]
        > page, the IDE will help use create a code-hehind class file together with
        > the page. Then, we can write the serverside event handler, such as server
        > control's click even's handler in the code-behind class file(.aspx.cs or
        > aspx.vb files). For example:
        > private void Page_Load(objec t sender, System.EventArg s e) // page's click
        > event handler
        > {
        > ...............
        >
        > }
        >
        > private void btnPrint_Click( object sender, System.EventArg s e) // a[/color]
        certain[color=blue]
        > button's click handler
        > {
        > ...............
        >
        > }
        >
        > these serverside event handlers normally all take two paramteres,one
        > (sender) is the source of the event, and the other (e, EventArgs or its
        > derived class) contains some infos of the event. When we add the handler[/color]
        to[color=blue]
        > a certain control's event's handler collection, we only need to provide[/color]
        the[color=blue]
        > function's name , not argument list needed, for example:
        >
        > this.btnPrint.C lick += new System.EventHan dler(this.btnPr int_Click);
        > this.Load += new System.EventHan dler(this.Page_ Load);
        >
        > However, if we don't use the code-behind page class file, then we just
        > write these handler functions in the aspx file and in such code blocks as
        > below:
        > <script language="C#" runat="server">
        > ....
        > private void btnPrint_Click( object sender, System.EventArg s e) // a[/color]
        certain[color=blue]
        > button's click handler
        > {
        > ...............
        >
        > }
        > </script>
        >
        > and we also speify the handler for a ASP.NET server control in the file
        > like:
        > <asp:button id="btnPrint" runat="server" Text="Print"
        > OnClick="btnPri nt_Click"></asp:button>
        > Just the function name, no parameter needed. Since the ASP.NET runtime[/color]
        will[color=blue]
        > help you to generate the "sender" and "e" object from the control
        > automaitcally.
        > For more detailed info on event handler in ASP.NET serverside , you may
        > view the following reference in MSDN:
        >[/color]
        http://msdn.microsoft.com/library/en...andlers.asp?fr[color=blue]
        > ame=true
        >
        > #Creating Event Handlers in Web Forms Pages
        >[/color]
        http://msdn.microsoft.com/library/en...ngEventHandler[color=blue]
        > sInWebFormsPage s.asp?frame=tru e
        >
        >
        > 2. The function I discussed in 1. is the server side code in ASP.NET. In
        > addition, we can write client side script code such as javascript in the
        > aspx page source file, for example:
        > <script language="javas cript">
        > function jsfn()
        > {
        > alert("hello world!");
        > }
        >
        > function sayHello(name)
        > {
        > alert("hello world" + name);
        > }
        > </script>
        >
        > But be careful, such client side script is quite different from the
        > serverside code, they only runat the client's browser. You can see the
        > <script ..> block doesn't have "runat=serv er". And the client side[/color]
        script's[color=blue]
        > function could also take paramter or doesn't take parameter. I've shown[/color]
        the[color=blue]
        > two condition in the above example.
        > If you need more information on clientside scripting, you may view the
        > following link for reference:
        >
        > #javascript overview and examples
        >[/color]
        http://msdn.microsoft.com/library/en...t.asp?frame=tr[color=blue]
        > ue
        >
        >
        > Please check out the above items to see whether they help. If you need any
        > further assistance, please feel free to let me know.
        >
        >
        > Regards,
        >
        > Steven Cheng
        > Microsoft Online Support
        >
        > Get Secure! www.microsoft.com/security
        > (This posting is provided "AS IS", with no warranties, and confers no
        > rights.)
        >[/color]


        Comment

        Working...