Results 1 to 2 of 2

Thread: [RESOLVED] ASP, C# Question.

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Resolved [RESOLVED] ASP, C# Question.

    I am working on some code that was originally written by someone else.
    Below is a sample of what one of the file look like. Of course there is much more in the main body of the code but for purposes of this question this should be enough.
    Code:
    <%@ Page Language="C#" Debug="true" %>
    <%@Import Namespace="System.Data" %>
    <%@Import Namespace="System.Data.OleDb" %>
    <%@Import Namespace="System.IO" %>
    <%@Import Namespace="System.Text" %>
    
    <%	
    	Response.Write("Test");			
    %>
    My issue is that I want to add one or more functions that are called from the main body of this code and I can't figure out how to do it properly.
    This aspx file is called from some javascript in an html page, does some processing and returns some data back to the page.

    For starters I want to add a logging function but all my attempts have failed.

    So the question is can I add a function to this file somehow and have it called from the main body? If not then is there a way I can have the functions in another script file and call them from the main body?

    Any link or working example would be very helpful.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: ASP, C# Question.

    Looks like I figured it out.

    TestMe.aspx
    Code:
    <%@ Page Language="C#" Debug="true" CodeFile="testme.aspx.cs" Inherits="TestMe"%>
    <%@Import Namespace="System.Data" %>
    <%@Import Namespace="System.Data.OleDb" %>
    <%@Import Namespace="System.IO" %>
    <%@Import Namespace="System.Text" %>
    
    <%	
    	Response.Write("Test");	
    	Func1();
    	
    %>
    TestMe.aspx.cs
    Code:
    using System;
    using System.Data;
    using System.Data.OleDb;
    using System.IO;
    using System.Text;
    public partial class TestMe : System.Web.UI.Page
    {
        public void Func1(){
            Response.Write("Function 1");
            return;
        }
    }
    This appears to work properly

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width