thukralz

Hello Everyone,

How to access these public partial classes:

I have something like this

public partial class test : System.Web.UI.Page

{

// What ever I need here

}

I have a second class

public partial class test1 : System.Web.UI.Page

{

//Code here

How can I access test from here

}



Re: Visual C# General Public partial classes

Gabriel Lozano-Moran

If test has some public/internal members that are static thus type members that you just need to access them by specifying the full namespace (unless they are in the same namespace) followed by test.

If you want to access instance members (not static members) than you need to create an instance first of test in test1 to be able to access them.

In test1:

test _test = new test();

Then if you have a method Foo():

public void Foo()
{
_test.FooInTest();
}






Re: Visual C# General Public partial classes

Harsimrat

I tried that doesn't work for me...



Re: Visual C# General Public partial classes

boban.s

Those are two different classess. Partial have nothing to do with having access between two different classes. Either you should have one class, or to access the first one trough an instance of it for nonstatic members. Or you can inherit test1 from test if that will work for you.




Re: Visual C# General Public partial classes

Harsimrat

Thats what bugging me is, If I create some seperate class works fine, but these public partial is giving me no luck...can you provide an example..



Re: Visual C# General Public partial classes

boban.s

partial keyword is not access modifier. It just represent intent to split type definition to multiple files. If you can't access some other type than the problem is either from access modifier of that type or that you don't reference or/and don't use namespace of that type. Probably those two types are in different namespace or/and different assembly.




Re: Visual C# General Public partial classes

Kusala

Hi Harsimrat,

 

Can you tell me what actually you want ot do here It seems to be you are trying to access one asp.net web page form another. Are you trying to pass values form one web page to another  

 

When you are doing the web programming, you have to understand web (http) is stateless model. So do things with this awareness.

 

The purpose of partial classes is to allow a class's definition to span across multiple files and it will not cause any problem to existing programming model.





Re: Visual C# General Public partial classes

Harsimrat

Hello kusala,

Yes, that is exactly what I'm trying to do...I don't want to pass any values, simply call a function available in another asp.net page....

When I read over public partial classes, it said you should be able to call the other pages no problem...Apparently not.....I have solved the problem by using Server.Transfer....

I'm stil curious If I need to call some specific function how will I do that...





Re: Visual C# General Public partial classes

Kusala

OK, understood the requirement. So does something like this:

Just say you have 2 asp.net pages called PageOne.aspx and PageTwo.sapx. In PageOne.aspx put a button and add the following code as well

public int AddTwoInt(int Num1, int Num2)
{
return Num1 + Num2;
}

protected void btnNextPage_Click(object sender, EventArgs e)
{
Server.Transfer("PageTwo.aspx");
}

Now in the PageTwo.sapx you can access method in PageOne.aspx (AddTwoInt) as follows

protected void Page_Load(object sender, EventArgs e)
{
PageOne P1 = (PageOne)Context.Handler;
Response.Write("Sum of 5 and 15 is equal to " + P1.AddTwoInt(5, 15));
}

For more information about value passing in between pages, please look at following forum comments (actually last one)

http://dotnetforum.lk/forums/20680/ShowPost.aspx