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
    ------------------

  • Ravikanth[MVP]

    #2
    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

      #3
      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

      • JH

        #4
        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

        Working...