Public Static Variable Declared In Public Static Class MyGlobals In A 'Code File' Template?
Jan 27, 2011
I have a question about C Sharp ASP.NET:Is there a difference (in code speed, resources) between:public static variable declared in public static class MyGlobals in a 'Code File' template;and the variable declared in a normal 'Class File' template;I use this variable in 2 different Class Files and also in _Default Page codebehind cs file.In fact in my case I need about 20 global variables of type List<string>.
View 9 Replies
Similar Messages:
Feb 10, 2011
I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.
I know its got to be something simple but I can't seem to find the answer anywhere.
View 1 Replies
Mar 23, 2011
Can I put public static int[] MyArrayCounter declared in separate class Main.cs into webpage Default.aspx between code tags <%= %>?
More info of what i do:
I have declaration in Main.cs:
[Code]....
In class Checking.cs i fill MyArrayCounter with 29 values. After code execution ends, i'd like my Default.aspx page to bind to that MyArrayCounter values like:
Label1.Text = MyArrayCounter[0]
Label2.Text = MyArrayCounter[1]
etc.
View 2 Replies
Jun 22, 2010
Let's say I have the following;
public static void TryOut(int intOne, int intTwo, string strone, string strtwo){....}
And after I created dll, I will use it like that;
TryOut(1,3,"bla bla bla", "bla bla bla");
But I want the last variable to be optional. I mean this method could be used like that;
TryOut(1,3,"bla bla bla", "bla bla bla");
And Also like that
TryOut(1,3,"bla bla bla");
I know it is possibel but how I could do that I have no idea !
View 5 Replies
Nov 11, 2010
For reasons I would rather not discuss, I need to create a custom authentication system for my app. I was just reviewing the system and am having some doubts if my solution is thread safe. My goal was to create a solution that would allow my app to authenticate a user one time and that users authentication info would be shared by all master pages, pages, classes, user controls, etc that are used. (But not share the same info between users) Here is my setup: PageHttpModule.cs - this is added to the web.config as a httpModule.
public class PageHttpModule : IHttpModule
{
public void Init(HttpApplication app)
{
app.AuthenticateRequest += new EventHandler(OnAuthenticateRequest);
}
public void OnAuthenticateRequest(Object s, EventArgs e)
{
CurrentUser.Initialize();
}
public void Dispose() { }
}
CurrentUser.cs
public static class CurrentUser
{
public static bool IsAuthenticated { get; private set; }
public static string Email {get; set;}
public static string RealName {get; set;
public static string UserId {get; set;}
public static void Initialize()
{
CurrentUser.AuthenticateUser();
}
Note: this is a scaled down version of my authentication code.
public static void AuthenticateUser()
{
UserAuthentication user = new UserAuthentication();
user.AuthenticateUser();
if (user.IsAuthenticated)
{
CurrentUser.IsAuthenticated = true;
CurrentUser.UserId = user.UserId;
CurrentUser.Email = user.Email;
CurrentUser.RealName = user.RealName;
}
}
}
UserAuthentication.cs
public class UserAuthentication
{
public string Email { get; set; }
public string RealName { get; set; }
public string UserId { get; set; }
public bool IsAuthenticated { get; private set; }
public UserAuthentication()
{
IsAuthenticated = false;
Email = String.Empty;
RealName = String.Empty;
UserId = String.Empty;
}
public void AuthenticateUser()
{
//do some logic here.. if the user is ok then
IsAuthenticated = true
Email = address from db
UserId = userid from db;
Realname = name from db;
}
}
I have tested between 3 different browsers and it seems to work fine, but I am still learning and don't want to make a huge mistake. If my logic is totally wrong, then how should I do it so I dont have to put user lookups on every page directly?
View 4 Replies
Aug 17, 2010
I have an app that I am testing with NUNit. The project im testing has several helper classes that are created as public static readonly. When I run the NUnit tests, they all fail with the same error
Systems.Code.Test.TransactionTest.CreateDataContext_ConnectionString_ReturnsDataContextObject:
View 2 Replies
Aug 19, 2010
I'm coding a business layer for an ASP.NET application. I've created database methods in my BLL as static. I've created public static Func variables to be compiled and used in several different methods, like this:
namespace BLL
public class User
{
public static Func<Context, variable, result> selectUser;
private static void CompileQuery()
{
if(selectUser == null)
{
selectUser = CompiledQuery.Compile......
}
}
public static UserClass Select(int id)
{
CompileQuery();
//uses selectUser
}
public static SomethingElse DoSomethingElse()
{
CompileQuery();
//also uses selectUser
}
}
It'll be used in ASP.NET layer like this: using BLL;
private void AddUser()
{
UserClass user = User.Select(id);
}
My question is, since static variables are not thread-safe, is this a bad design decision? I'm thinking of either implementing a locking mechanism, which makes me think if it'd slow down the application, or using instantiated class approach which makes me wonder if query compiling would be beneficial.
View 1 Replies
Aug 26, 2010
How do declare a public variable .aspx web page that can be used in all the pages within my web application? And/or create a Public Sub?
View 3 Replies
Mar 7, 2010
[Code]....
The variable is assigned a value in another class like this:
[Code]....
View 1 Replies
Feb 22, 2011
I have defined a public static HashTable. It stores data for a few seconds of runtime, and then data disappears, and then the HashTable becomes null.What is the issue and how do I solve it?
View 1 Replies
Mar 26, 2011
I have a private static field in my Controller class in an MVC web application.
I have a static method in that controller that assigns some value to that static field, I want to apply lock on that static field until some other instance method in the controller uses the value stored in the static field and then releases it.
DETAILS:
I have a controller named BaseController having a static ClientId field as follows and two methods as follows:-
public static string ClientId = "";
static void OnClientConnected(string clientId, ref Dictionary<string, object> list)
{
list.Add("a", "b");
// I want the ClientId to be locked here, so that it can not be accessed by other requests coming to the server and wait for ClientId to be released:-
BaseController.clientId = clientId;
}
public ActionResult Handler()
{
if (something)
{
// use the static ClientId here
}
// Release the ClientId here, so it can now be used by other web requests coming to the server.
return View();
}
View 1 Replies
Apr 10, 2010
I have a problem to pass along public variables from C# code to the HTML code. I assign the variables in the Page_Load event and then pass along them to the Panel and Image control in the HTML code. Though I get this compileerror for the Width: "Cannot create an object of type "System.Web.UI.EbControls.Unit" from its string representation '<%setWidthImage%>' for the 'Width' property."
[Code]....
View 7 Replies
May 9, 2010
I'd like to know how to declare a variable in my code behind page that I can use in all the subs of my code behind.
I tried in after the Partial Class declaration to declare a "Public String" :
[Code]....
and to use it in my subs but when I use it from a sub to another I loose the value affected in another sub.
Is there a way to use a Public variable from a sub to another (I'm actually using a session variable in order to do it and I'm not sure it is the best way)
View 4 Replies
Jul 28, 2011
I understand the problem of the static variable inside a class in the web application, now I try to create a simple class to deal with SQL Server for example, so I created Static Method inside this class, this static method used in insert, update and delete from database, I wonder if this is safe, and there is no problems will appear ?
View 10 Replies
Feb 23, 2011
I created a webpage names Default.aspx. In its code behind i defined another public class named Test. Test class is not accessible in other pages code behind although it is defined as public.
View 8 Replies
Nov 18, 2010
I need to keep a global variable throughout the whole time the user is at my site, but do I use Application or a static class? The string variable should store a region name and my site makes a few changes depending on which region that has been set.
I read that Application was mainly for classic ASP, but I also read that a static class cannot be instantiated at runtime (e.g. when the user has logged in).
So, have I got something wrong here and which solution do I use?
View 2 Replies
Feb 10, 2010
i have written following code to access public variable of asp.net onclick event on button but its not giving me desired output.. please check it:
<asp:Button runat="server" CssClass="txtdisplay" ID="Button1"
Text="Browse all jobs in area"
OnClientClick="return navigateURL('index.aspx?c=<%=cityid %>')" />
View 1 Replies
Mar 29, 2010
Can a dataview be declared as public?
Dim dvEditTreatmentType As DataView = New DataView(dsTreatmentEndDate.Tables(0), "IsNull(DialysisEndDate, '') = ''", "", DataViewRowState.CurrentRows)
can this be declared as public Dataview? is there a way to do it?
View 2 Replies
Dec 2, 2010
Is there a way to call a public function from a class?
[code]....
View 4 Replies
Sep 28, 2010
I want to access the static variable in my global.ashx file I am using classname.variable name for accessing the variable but the variable name dose not appear.Can someone tell me how to access static varialbe in *.ashx file.
View 5 Replies
Apr 4, 2010
Can we declare a static method inside the Interface?If not means Why?
View 4 Replies
May 17, 2010
I have a web application which uses a session variable to store the logged in userid. If no user is logged in, of course this variable will be empty and the contents displayed on my website are meant for guests. If there is a user logged in, the user specific controls/access/links will then be a displayed.
I am now having issues with my hosting where on shared application pool, the worker recycle is triggered every 90 minutes, this will clear sessions causing all my users to be logged out. I opted for a dedicated application pool, which got worse because I am only allocated 50MB memory limit and if this is reached, the worker recycle is triggered and I lose my sessions again. I have tried as much as possible optimization techniques, e.g. dispose where possible, close connections, disable viewstate for static controls etc but my memory per instance keeps building up from page to page without any signs of improvement. I don't use loops nor store huge objects like bitmaps etc but my sessions are now gone even faster than 90 minutes in shared application pool before.
I have considered using SQL Session State but there isn't a simple guide on using this with MySQL. I am getting desperate and considering using a public variable, a string as a replacement to store logged in user id instead of in a session variable. I am pretty sure this will solve my issue with sessions being recycled but are there any negative consequences of doing this? One problem I can think of is if the user closes the browser, the system will never know that the user is now logged out and this public variable should be nothing. In this scenario, will the GC eventually clear this abandoned public variable.
View 10 Replies
Feb 1, 2013
While understanding the basic concept of inheritance in internet, i came across a piece of code.
I've seen many people using public static void main().Why dont they simply use public void main() ??What's the advantage of using static here ?
Public class BaseClass {
Public BaseClass () {
Console.WriteLine ("Base Class Constructor executed");
} Public void Write () {
Console.WriteLine ("Write method in Base Class executed");
[Code] .....
View 1 Replies
Mar 28, 2011
public static string SEARCH_STRING = "searchkey";
string key=Request.QueryString.Get(SEARCH_STRING);
How to change the above code to make SEARCH_STRING be accessed using a Property(get; set;) instead of a public variable
View 8 Replies
May 28, 2010
have a look at the code:
[Code]....
Here When i create object of Class InheritingOneConstruntor value of public field var1 is zero at last. But when i checked step by step through debugging i found that when base class's New() constructor is called, for a moment all var1's value becomes 89. All var1 means at all locations where var1 is used i.e., in base class and in child class.But the moment control exits New() constructor of base class, var1's value again becomes zero. Why it happend ?
View 7 Replies