Can I call a function defined in one partial class from another partial class. Is it possible?

I created two partial classes for a web page.

Now I have given protection to one say submit () function that I call in the OnSubmit event.

But this function is not called, the program does not compile, because it cannot search for the defination function that was defined in another partial class. Is it possible to call this function, or should I give a defination function in the same file where I call it

eg,

<%@ Page Language="C#" MasterPageFile="~/Master Pages/LeftMenu.master" AutoEventWireup="true" CodeFile="Registration.aspx.cs" Inherits="Web_Pages_Authentication_Login_Management_Registration" Title="Registration" StylesheetTheme="Default Theme 1"  %>

Registration.aspx.cs

public partial class Web_Pages_Authentication_Login_Management_Registration : System.Web.UI.Page
{
    private string firstName;
    private string lastName;
    private string userName;
    private string userPassword;
    private string primaryEmail;
protected void btnSubmit_Click(object sender, EventArgs e)
    {
       Display();
    }
}

Registration_Database.cs

   public partial class Web_Pages_Authentication_Login_Management_Registration 
    {
       const string dbFirstName = "@FirstName";
       const string dbLastName = "@LastName";
       const string dbUserName= "@UserName";
       const string dbUserPassword = "@UserPassword";
       const string dbPrimaryEmail = "@PrimaryEmail";  

       void Display()
          {
              firstName="XYZ"; //This variable is not accessible when i put both files in different directories
          }
    }

I get the following error

Error   1   'Web_Pages_Authentication_Login_Management_Registration' does not contain a definition for 'Display' and no extension method 'Display' accepting a first argument of type 'Web_Pages_Authentication_Login_Management_Registration' could be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrator\Desktop\Online Test\Web Pages\Authentication\Login Management\Registration.aspx.cs  78  20  C:\...\Online Test\

Registration.aspx, Registration.aspx.cs, Registration_Database.cs - , App_Code, , Registration.aspx.cs, Registration_Database.cs Registration.aspx . Plz ,

DLL.

+5
5

, , , , , -.

ASP.NET , , , .cs . , display(), , , .

, , , , , , , , , System.Web.UI.Page, . App_Code -.

Registration.aspx.cs:

public partial class Web_Pages_Authentication_Login_Management_Registration : MyPage
{
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Display();
    }
}

App_Code\MyPage.cs:

public class MyPage : System.Web.UI.Page
{
    protected void Display()
    {
        // ...
    }
}

: , , , , , . , . , , , .

, App_Code . ( , , ). :)

+5

, . ( ), ClassName.MethodName() instanceName.MethodName()

EDIT: , .

. , . , , , .

+1

, () .

( #) - IL, .

, . , .

:

namespace MyNamespace
{
    public partial class MyClass { }

    public partial class MyClass { }
}

Thre - MyNamespace.MyClass. :

namespace MyNamespace
{
    public partial class MyClass
    {
        public void MyMethod();
    }
}

namespace MyOtherNamespace
{
    public partial class MyClass { }
}

: MyNamespace.MyClass MyOtherNamespace.MyClass. this.MyMethod MyOtherNamespace.MyClass .

+1

. , , ; . , , , :

partial class Foo
{
    partial void Bar(string someArg);
    // other code that uses Bar(s)
}
partial class Foo
{
    partial void Bar(string someArg)
    {
        Console.WriteLine(someArg);
    }
}

, partial out -void return.

+1

, , SAME. ? ?

, , . , .

, , . , , , .

0

All Articles