Unfortunately variables aren't global. They're scoped to the page you're working on.
For now you have to build your own class with a method that sets up your class and call that from every page.
Drop a file called DALHelpers.cs into the App_Code in the root of your app. Put this in the file...
public static class DALHelpers {
public static DAL CreateDAL() {
DAL mydll = new DAL();
mydll.ConnectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"];
return mydll;
}
}
From any page now you can do this...
@{
var mydll = DALHelpers.CreateDAL();
var data= mydll.getfunction(year, username, out ex);
Response.Write(data);
}
Not ideal, but should work for you. In the next release we'll allow you to put an @functions {} block into a file in App_Code and the methods will be globally accessible to any page. That should simplify it a bit.
HumanCompile...
Member
511 Points
100 Posts
Microsoft
Re: How to add WebMatrix default parameters?
Aug 11, 2010 10:18 PM|LINK
Unfortunately variables aren't global. They're scoped to the page you're working on.
For now you have to build your own class with a method that sets up your class and call that from every page.
Drop a file called DALHelpers.cs into the App_Code in the root of your app. Put this in the file...
public static class DALHelpers { public static DAL CreateDAL() { DAL mydll = new DAL(); mydll.ConnectionString = (string)ConfigurationSettings.AppSettings["ConnectionString"]; return mydll; } }From any page now you can do this...
@{ var mydll = DALHelpers.CreateDAL(); var data= mydll.getfunction(year, username, out ex); Response.Write(data); }Not ideal, but should work for you. In the next release we'll allow you to put an @functions {} block into a file in App_Code and the methods will be globally accessible to any page. That should simplify it a bit.
ASP.NET PM
http://about.me/erikporter