Include file

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

    #1

    Include file

    I'm new in the .NET world, so sorry if this is a faq. In classic ASP I
    often use a include file with some standard functions, ex. formating a
    string an so. How do a do this i .NET ??

    In my test code below, I submit a form with a textbox, use the
    function "format_str ing" to change the value. I would like to use this
    function in other scripts also, so need to place the code in another
    file, and include it, how ?

    I'll appreciate if someone could change my test code, to show me the
    right way to do it.

    Thx..



    test.aspx
    ------------------
    <%@ page language="vb" inherits="test" src="test.vb" %>
    <html>
    <head>
    </head>

    <body>
    <form id="test" method="post" runat="server">
    <asp:textbox id="sometext" text="" runat="server" />
    <asp:button id="submit" text="submit" onclick="test_m e"
    runat="server" />
    </form>
    </body>
    </html>
    ------------------


    test.vb
    ------------------
    Imports System
    Imports System.Web.UI

    public class test : inherits page
    sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
    dim sometext as string
    sometext = format_string(R equest.Form("so metext"))
    end sub

    function format_string(v alue as string) as string
    return "!" & value & "!"
    end function
    end class
    ------------------

  • Hugo Wetterberg

    #2
    Re: Include file

    On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:

    Everything is compiled into a single dll if it resides in the same
    project. All the classes and pages can use functions from each other.

    I've sent another post with what I think is the VB equivalent of what
    I posted in my first reply.
    [color=blue][color=green]
    >> The easiest way would be to make some utility classes.[/color]
    >
    >Thanks for your reply.... I like the idea with a "utility class".
    >
    >
    >I put this code in ex. "StringUtilitie s.vb", and place it in a shared
    >include-folder
    >-----[color=green]
    >> public class StringUtilities
    >> {
    >> public static string FormatString(st ring s)
    >> {
    >> string result;
    >>
    >> //Do something
    >> return result;
    >> }
    >> }[/color]
    >-----
    >
    >How do my codebehind code (test.vb) know about the class
    >"StringUtiliti es" ??
    >-----[color=green]
    >> private void Page_Load(...)
    >> {
    >> string s="Hello 123";
    >> s=StringUtiliti es.FormatString (s);
    >> }[/color]
    >-----[/color]

    Comment

    • Hugo Wetterberg

      #3
      Re: Include file

      On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:

      Sorry here's the post I should have sent before:

      Saw that you are using VB, but it should be the same principle.
      Separate the format string subroutine from the page and put it in a
      class:

      public class StringUtilities

      public static function format_string(v alue as string) as string
      return "!" & value & "!"
      end function

      end class

      then change sub test_me to:

      sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
      dim sometext as string
      sometext = StringUtilities .format_string( Request.Form("s ometext"))
      end sub

      Something like that anyway.
      Cheers, Hugo

      Comment

      • joe

        #4
        Re: Include file

        Do you (can you) place these utility classes in a separate code file where
        they will be available to all parts of the application and reusable in other
        applications? If so what type (extension) of file do you create?

        thanks




        "Hugo Wetterberg" <hugo@wetterber g.com> wrote in message
        news:b1hvhvo7fl 5mia86a8qsmvk98 phumdnjot@4ax.c om...[color=blue]
        > On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:
        >
        > Sorry here's the post I should have sent before:
        >
        > Saw that you are using VB, but it should be the same principle.
        > Separate the format string subroutine from the page and put it in a
        > class:
        >
        > public class StringUtilities
        >
        > public static function format_string(v alue as string) as string
        > return "!" & value & "!"
        > end function
        >
        > end class
        >
        > then change sub test_me to:
        >
        > sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
        > dim sometext as string
        > sometext = StringUtilities .format_string( Request.Form("s ometext"))
        > end sub
        >
        > Something like that anyway.
        > Cheers, Hugo[/color]


        Comment

        • Ravikanth[MVP]

          #5
          Include file

          Hi

          Check out the following articles, which tells about How
          to include files in aspx.


          articleID=9


          ..asp

          Ravikanth

          [color=blue]
          >-----Original Message-----
          >I'm new in the .NET world, so sorry if this is a faq. In[/color]
          classic ASP I[color=blue]
          >often use a include file with some standard functions,[/color]
          ex. formating a[color=blue]
          >string an so. How do a do this i .NET ??
          >
          >In my test code below, I submit a form with a textbox,[/color]
          use the[color=blue]
          >function "format_str ing" to change the value. I would[/color]
          like to use this[color=blue]
          >function in other scripts also, so need to place the[/color]
          code in another[color=blue]
          >file, and include it, how ?
          >
          >I'll appreciate if someone could change my test code, to[/color]
          show me the[color=blue]
          >right way to do it.
          >
          >Thx..
          >
          >
          >
          >test.aspx
          >------------------
          ><%@ page language="vb" inherits="test" src="test.vb" %>
          ><html>
          > <head>
          > </head>
          >
          > <body>
          > <form id="test" method="post" runat="server">
          > <asp:textbox id="sometext" text="" runat="server" />
          > <asp:button id="submit" text="submit"[/color]
          onclick="test_m e"[color=blue]
          >runat="serve r" />
          > </form>
          > </body>
          ></html>
          >------------------
          >
          >
          >test.vb
          >------------------
          >Imports System
          >Imports System.Web.UI
          >
          >public class test : inherits page
          > sub test_me(ByVal Sender As Object, ByVal E As[/color]
          EventArgs)[color=blue]
          > dim sometext as string
          > sometext = format_string(R equest.Form("so metext"))
          > end sub
          >
          > function format_string(v alue as string) as string
          > return "!" & value & "!"
          > end function
          >end class
          >------------------
          >
          >.
          >[/color]

          Comment

          • Hugo Wetterberg

            #6
            Re: Include file

            The easiest way would be to make some utility classes.

            public class StringUtilities
            {
            public static string FormatString(st ring s)
            {
            string result;

            //Do something
            return result;
            }
            }


            And then in the code-behind you just use the class:

            private void Page_Load(...)
            {
            string s="Hello 123";
            s=StringUtiliti es.FormatString (s);
            }

            I hope this helps
            Hugo

            Comment

            • Hugo Wetterberg

              #7
              Re: Include file

              On Thu, 24 Jul 2003 07:55:21 -0400, "joe"
              <contact_by_New sgroup_only.ple ase> wrote:

              Yes. That is the beauty with .net. Start a new class library project
              (or set the compilation target to library). The output from
              compilation will be a dll that you can reference to from your other
              projects.
              [color=blue]
              >Do you (can you) place these utility classes in a separate code file where
              >they will be available to all parts of the application and reusable in other
              >applications ? If so what type (extension) of file do you create?
              >
              >thanks
              >
              >
              >
              >
              >"Hugo Wetterberg" <hugo@wetterber g.com> wrote in message
              >news:b1hvhvo7f l5mia86a8qsmvk9 8phumdnjot@4ax. com...[color=green]
              >> On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:
              >>
              >> Sorry here's the post I should have sent before:
              >>
              >> Saw that you are using VB, but it should be the same principle.
              >> Separate the format string subroutine from the page and put it in a
              >> class:
              >>
              >> public class StringUtilities
              >>
              >> public static function format_string(v alue as string) as string
              >> return "!" & value & "!"
              >> end function
              >>
              >> end class
              >>
              >> then change sub test_me to:
              >>
              >> sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
              >> dim sometext as string
              >> sometext = StringUtilities .format_string( Request.Form("s ometext"))
              >> end sub
              >>
              >> Something like that anyway.
              >> Cheers, Hugo[/color]
              >[/color]

              Comment

              • JH

                #8
                Re: Include file

                > The easiest way would be to make some utility classes.

                Thanks for your reply.... I like the idea with a "utility class".


                I put this code in ex. "StringUtilitie s.vb", and place it in a shared
                include-folder
                -----[color=blue]
                > public class StringUtilities
                > {
                > public static string FormatString(st ring s)
                > {
                > string result;
                >
                > //Do something
                > return result;
                > }
                > }[/color]
                -----

                How do my codebehind code (test.vb) know about the class
                "StringUtilitie s" ??
                -----[color=blue]
                > private void Page_Load(...)
                > {
                > string s="Hello 123";
                > s=StringUtiliti es.FormatString (s);
                > }[/color]
                -----

                Comment

                • Hugo Wetterberg

                  #9
                  Re: Include file

                  On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:

                  Everything is compiled into a single dll if it resides in the same
                  project. All the classes and pages can use functions from each other.

                  I've sent another post with what I think is the VB equivalent of what
                  I posted in my first reply.
                  [color=blue][color=green]
                  >> The easiest way would be to make some utility classes.[/color]
                  >
                  >Thanks for your reply.... I like the idea with a "utility class".
                  >
                  >
                  >I put this code in ex. "StringUtilitie s.vb", and place it in a shared
                  >include-folder
                  >-----[color=green]
                  >> public class StringUtilities
                  >> {
                  >> public static string FormatString(st ring s)
                  >> {
                  >> string result;
                  >>
                  >> //Do something
                  >> return result;
                  >> }
                  >> }[/color]
                  >-----
                  >
                  >How do my codebehind code (test.vb) know about the class
                  >"StringUtiliti es" ??
                  >-----[color=green]
                  >> private void Page_Load(...)
                  >> {
                  >> string s="Hello 123";
                  >> s=StringUtiliti es.FormatString (s);
                  >> }[/color]
                  >-----[/color]

                  Comment

                  • Hugo Wetterberg

                    #10
                    Re: Include file

                    On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:

                    Sorry here's the post I should have sent before:

                    Saw that you are using VB, but it should be the same principle.
                    Separate the format string subroutine from the page and put it in a
                    class:

                    public class StringUtilities

                    public static function format_string(v alue as string) as string
                    return "!" & value & "!"
                    end function

                    end class

                    then change sub test_me to:

                    sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
                    dim sometext as string
                    sometext = StringUtilities .format_string( Request.Form("s ometext"))
                    end sub

                    Something like that anyway.
                    Cheers, Hugo

                    Comment

                    • joe

                      #11
                      Re: Include file

                      Do you (can you) place these utility classes in a separate code file where
                      they will be available to all parts of the application and reusable in other
                      applications? If so what type (extension) of file do you create?

                      thanks




                      "Hugo Wetterberg" <hugo@wetterber g.com> wrote in message
                      news:b1hvhvo7fl 5mia86a8qsmvk98 phumdnjot@4ax.c om...[color=blue]
                      > On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:
                      >
                      > Sorry here's the post I should have sent before:
                      >
                      > Saw that you are using VB, but it should be the same principle.
                      > Separate the format string subroutine from the page and put it in a
                      > class:
                      >
                      > public class StringUtilities
                      >
                      > public static function format_string(v alue as string) as string
                      > return "!" & value & "!"
                      > end function
                      >
                      > end class
                      >
                      > then change sub test_me to:
                      >
                      > sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
                      > dim sometext as string
                      > sometext = StringUtilities .format_string( Request.Form("s ometext"))
                      > end sub
                      >
                      > Something like that anyway.
                      > Cheers, Hugo[/color]


                      Comment

                      • Hugo Wetterberg

                        #12
                        Re: Include file

                        On Thu, 24 Jul 2003 07:55:21 -0400, "joe"
                        <contact_by_New sgroup_only.ple ase> wrote:

                        Yes. That is the beauty with .net. Start a new class library project
                        (or set the compilation target to library). The output from
                        compilation will be a dll that you can reference to from your other
                        projects.
                        [color=blue]
                        >Do you (can you) place these utility classes in a separate code file where
                        >they will be available to all parts of the application and reusable in other
                        >applications ? If so what type (extension) of file do you create?
                        >
                        >thanks
                        >
                        >
                        >
                        >
                        >"Hugo Wetterberg" <hugo@wetterber g.com> wrote in message
                        >news:b1hvhvo7f l5mia86a8qsmvk9 8phumdnjot@4ax. com...[color=green]
                        >> On Thu, 24 Jul 2003 11:14:00 GMT, JH <003___remove__ _@email.dk> wrote:
                        >>
                        >> Sorry here's the post I should have sent before:
                        >>
                        >> Saw that you are using VB, but it should be the same principle.
                        >> Separate the format string subroutine from the page and put it in a
                        >> class:
                        >>
                        >> public class StringUtilities
                        >>
                        >> public static function format_string(v alue as string) as string
                        >> return "!" & value & "!"
                        >> end function
                        >>
                        >> end class
                        >>
                        >> then change sub test_me to:
                        >>
                        >> sub test_me(ByVal Sender As Object, ByVal E As EventArgs)
                        >> dim sometext as string
                        >> sometext = StringUtilities .format_string( Request.Form("s ometext"))
                        >> end sub
                        >>
                        >> Something like that anyway.
                        >> Cheers, Hugo[/color]
                        >[/color]

                        Comment

                        Working...