tags:

views:

23

answers:

2

In VS 2010 I have created a test method in partial class stored in Default.Partial.aspx.cs within the same directory as Default.aspx.cs but it isn't recognized by the Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Default
/// </summary>
public partial class _Default : System.Web.UI.Page
{
    private void test() { 

    }

}

Code of default.partial.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        test();
    }
}

Update: if I add same namespace to both I get even weird message error I really don't understand partial class in asp.net whereas with winform I never encountered such problem !

+1  A: 

How are you trying to access the method?

If calling from outside the class, it will never show up, as it is private.

The same will happen in derived classes.

Solution, make the method public or protected.

leppie
@SLaks: What are you talking about? I never mentioned a partial method (although I have never heard of that limitation). As per the OP, it is just a plain method.
leppie
@leppie: Sorry; my mistake.
SLaks
He says that he's trying to access it from the `.cs` file, which isn't a derived class.
SLaks
I have added the source code where I call test() from default.aspx.cs
+1  A: 

Add a namespace (the exact same one) to both class files that you define the partial _Default class and you will have access to what you need.

TheGeekYouNeed
If neither class has a namespace, it will still work.
SLaks
You can see the source code: I have no namespace for both.
Did you try and add a namespace to both to see if it helps you at all? I know it isn't needed. However it can get you on the right track and help you figure out what the real problem is.
TheGeekYouNeed
Wow if I add namespace I get even weird message error I really don't understand partial class in asp.net whereas with winform I never encountered such problem !