Reputation: 145
I have declared a namespace in Feed.aspx.cs . This namespace contains a class and this class contains a method: Feed.aspx.cs
namespace GetUser
{
public class MyFeedClass
{
public string getUserID()
{
MembershipUser user = Membership.GetUser(HttpContext.Current.User.Identity.Name);
HttpContext.Current.Session["x"] = user.ProviderUserKey.ToString();
string test = (string)HttpContext.Current.Session["x"];
return test;
}
}
}
Now, from MyPage.aspx.cs, I'd like to call the getUserID() method. How can I do that?
Upvotes: 4
Views: 33388
Reputation: 887
Make sure you include the namespace in your code-behind:
using GetUser;
Make the public function a static one in the MyFeedClass:
public static string getUserID() {...}
Then in your aspx.cs page you can now try to do:
string userId = MyFeedClass.getUserID();
Upvotes: 0
Reputation: 11063
I guess you are using Asp.NET?
You should create a new class inside your add_code folder. Move that namespace and the class inside the new created class
Then call it from your Feed.aspx.cs:
GetUser.MyFeedClass myfeed = new GetUser.MyFeedClass();
string result = myfeed.getUserID();
Upvotes: 5