Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a small project in asp.net. I used a class to read & access the data as common. Now I don't know how to use it in aspx page. Also I can use it in aspx.cs no problem. But aspx page I cannot access the variable. Kindly advice me, thanks

MyDataToHold.cs
===============

public class My_GlobalData
    {
        public static System.Data.DataTable MyAddressTbl = new DataTable();
    }

In aspx.cs Page
System.Data.DataTable MyAdrsTbl = MyGlobalData.MyAddressTbl; // Working Good

But in aspx Page
System.Data.DataTable MyAdrsTbl = <%= My_GlobalData.MyAddressTbl %>;// ?????Not Working

Thanks Again

What I have tried:

Access the class declared public variable in aspx page
Posted
Updated 16-Aug-17 18:43pm

1 solution

try this

declare the variable in aspx.cs file
public partial class WebForm1 : System.Web.UI.Page
 {
     public System.Data.DataTable MyAdrsTbl;

and assign the value to the variable
<%=  MyAdrsTbl =  My_GlobalData.MyAddressTbl %>;
 
Share this answer
 
Comments
Paramu1973 17-Aug-17 3:07am    
No, I don't wish to use aspx.cs file, everything I need to use with in aspx page. Reciving error "My_GlobalData does not exist in the current context" Thank you
Karthik_Mahalingam 17-Aug-17 3:35am    
afaik, its not possible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900