Losing Data From Static Property Variable?
Feb 28, 2010public static int _CompanyId;
I am assigning some value to _CompanyId after login .After some post backs i lose value in_CompanyId .What could be the reason ?
public static int _CompanyId;
I am assigning some value to _CompanyId after login .After some post backs i lose value in_CompanyId .What could be the reason ?
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 RepliesI have got an ASP.Net website, where the data is brought in from ISeries.The data connection to ISeries is quite slow and the speed is quite important for this website. Because of the slow speed of data retrieval from ISeries, I want to make as less database connections as possible.So, I was thinking about storing tables from the database which rarely changes as static properties in my website. Whenevera user logs in I submit a thread which refreshes the data in the static property. Is this approach correct? If not, what are the problems with this approach and what are the possible alternatives?
Example:-
For list of ports, I submit the below thread when user logs on:-
[Code]....
In class Ports, there are 2 methods -
one for populating the static property PortList, and the other checks if the thread is alive and waits for the thread to complete and retrieve the list of ports, once it is complete. The second method is the one which I use in my application whenever I need the list of ports (populating a dropdown, etc).
[Code]....
So to pretty much make this short and sweet, I have a page variable defined outside of all my methods and functions called buttonpressed. It is used to keep track of which button has been pressed on the app. For example, in the onclick event of my Edit button there is a line:
buttonpressed = "Edit"
I use this to decide what kind of query to perform to my database. My problem is whenever I hit my save button(which uses that buttonpressed value in an if statement to decide what query to perform), the variable value just magically disappears.
I tracked the value to make sure that it is being changed and store correctly based on my add, edit, and delete buttons. As soon as I hit my save button, the value of that variable goes blank.
I have using Static Variable in My project.i want Change Static variable value because of transfer the value b/w two Forums... and I want Change value at run time...provide solution
Or else Any other way transfer value b/w two forms......
I'm fairly new to ASP.net development as may have been noticed by some of my other posts and so here goes another one.I have a web page in which I allow users to enter data that will be used to populate a database and then graph data based on the information that was saved in the database. I have 10 sets of criteria that the user can enter and as they enter values for each individual set, I make sure all the parameters are filled in and set a variable called blnParm1, blnParm2, blnParm3, etc. Anyway, as each DropDownList box fires off an event the values of my blnParm variables is reset because each time the event is fired the page is PostBack therefore my variables are redeclared. I know the page is being PostBack because each of the DropDownList boxes have AutoPostBack set to true. I had to do this so that I could get the OnSelectedIndexChanged event to fire for each of the DropDownList boxes. So, how do I preserve my variables through this PostBack or how do I get the events to trigger without calling AutoPostBack?
Some more info, my variables are declared globally in my aspx.cs file as private bool. The code is working like it should as far as populating drop downs dynamically based on other data input by the user, the controls all have their values preserved as the page is PostBack.
I had an interview today and every thing was going very good, but then an interviewer asked me a question Where Does Static Variable Work in C#- At Application Level or At Page Level.I was not very much clear about this answer as I only knew that static variables are stored on heap and I didn't knew anything about web related thing.
Then he tried to make me more clear by giving an example that in a page I am using static variable and three users are accessing the page one of the user updates the value of static variable, What value will be visible to remaining two users an old copy or the update will be reflected.
I dont know, but <%= %> doesnt allow me to enter my project namespace. Im trying to reference a static variable in another folder.
Ex: <%= Site.Web.Variable %>
I know the big difference, but one thing is confusing me. Cache works only on a single machine on webfarm and to make it globally we use Velocity or memcache.So is static does same, or is it already work globally ?
eg
Cache["someid"] = "value"; //this will only work on single machine cache,
static string abc = "value"; // will this work on single machine or globally ?
my asp.net app uses dynamic stylesheets. so each of my pages uses a pre_init method to load the relevant stylesheet. the stylesheet is the same for ALL users of the app.for each page load, i don't want to query the database to determine which stylesheet to use. therefore, I simply load the stylesheet from a STATIC variable that I store when the app starts.
works fine locally. however, on the production server the STATIC variable is reset to Null after about 5 minutes. why is that?? is there a better way for me to handle this? Should I change something in IIS? Should I change the methodolgoy I am using to retreive the stylesheet?
Each .aspx page includes:
[Code]....
BusinessLogic.Admin:
[Code]....
BusinessLogic.Admin parameter
[Code]....
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 RepliesI am using javascript to validate user input on my aspx page. I am easily able to validate textboxes and dropdown list for differenet scenarios.
Now, on one of my dropdown lists (for country), I need to check if it is an allowed country or not for a particular service. I have stored the valid country list in a static property. Is there a way to validate my dropdownlist selected value against that static property?
function validateService(source, args)
{
var country = document.getElementById('<%= ddDestCountry.ClientID %>');
var service = document.getElementById('<%= ddService.ClientID %>');
// Get allowed country list from my static class
var countryList = document.getElementById('<%= StaticProperties.EUCountryList %>');
if (service.value == "P")
{
// I want to do something like this
if (!countrylist.Contains(country.value))
{
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
return;
}
Update(Additional Information): The static property is read-only so it cannot be tampered with from the page.
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 RepliesI am creating a static variable and adding to session.This variable has value that is user specific. Now I am getting a problem with this users are complaining that they are getting values that should be another users. It's like a mix up with session. Could this be because of static variable declaration?
View 2 Replieswant to make sure I am not assuming something foolish here, when implementing the singleton pattern in an ASP .Net web application the static variable scope is only for the current user session, right? If a second user is accessing the site it is a different memory scope...?
View 4 RepliesWhat is difference between Application object and static variable? Where these are stroed in memory.
View 4 RepliesI want to know , how good / bad is it to save configuration values in a static properties?I am creating an application which reads configuration from an XML file and a DataContext file, instead of sending the CustomConfig class into the configuration.xml each time I tought about using an ReadXml() method on application_start at the global.ascx
the ReadXml() method would save the data in static properties of CustomConfig and whereever I would want to read that particler data I would ask CustomConfig.PROERTY_NAME
My question is ? how smart it is ? how long does IIS would save the data in a static member? (if as long as the application exists then I'm ok as long as I add the ReadXml() in the application_start)
I've always wondered how you can access the correct state of the current http context via a static method:
HttpContext.Current.Session["foo"] = "bar";
In any other program, anywhere else, my initial assumption about working with a static accessor like this is that changing it will change it across all threads. Similarly, another thread running my change it on me while I am trying to use it.But HttpContext.Current does not behave like this. It provides the appropriate state for the given request, even through the static accessor.
I'm using jQuery and setInterval method in my asp.net web application.
I call the webservice every 5 seconds in order to check for DB changes. When i see a change, i want to change the photo of the linkButton that located on the master page, but i can to that due to static constrains.
An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Master.get'
my c# code is:
[WebMethod()]
public static bool checkDBChange(string userId) {
DBConnection dbConnection = new DBConnection();
if (dbConnection.isChanged(userId)) {
((Site1)Master).SetImageUrl = "~/Icons/a.ico";
}
return false;
}
The SetImageUrl is a setter in my master page that sets the new url to the linkButton. How I can implement it?
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?
"'ErrorMessageResourceType' property specified was not found."
{"The resource type 'XXXX.XXXXXX' does not have a publicly visible static property named '_RequiredXXXX'."}
I'm getting this error when my Create.aspx view is called and steps over that line:
<%=Html.TextBoxFor(Function(model) model.NO_DEMND, New With {.class = "txtbox", .disabled = True})%>
<%=Html.ValidationMessageFor(Function(model) model.NO_DEMND)%>
The message is there in the Ressources file, I think the problem is deeper than that but i'm having a hard time finding it. It pops this error very early on the ASPX page. It's the first model component it goes thru, i tried removing this one and it's the same message for all the model.xxxx components. I guess it's an error somewhere in the linkage. The .EDMX is correct and I get no build errors,
I am getting a CS0120 error when trying turn a button visible after checking some variables. In plain english, If AmmohelpSession.UserActions contains AmmohelpEnums.UserAction.ArticleEdit then turn the Edit button visible. Here is my comparison:
[Code]....
In the code behind for AmmohelpSession, a public class AmmohelpSession which contains a private variable: private HashSet<UserAction> _userActions; has been stated. In that same file, there is a public function for the UserActions that does a get or set method.In the code behind for AmmohelpEnums, we are setting byte variables to specific actions. Mine would be something like:
[Code]....
Where is my error coming from ?????
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
I want to set the value of a session variable to a hex color code in the Global.asax, then use the value of that session variable (hex code) as the background color in the default.css file.
how to accomplish this?
I need to read a Property/variable from outside the webpart usercontrol to determine a course of action. This is not the same as using the Property Editor.
I have numerous usercontrol webparts all accessing the database.
When minimised, I don't want the webpart to hit the database.
So, I need to either : detect within the usercontrol webpart itself that its chromstate is minimised and therefore not access the database (and)or from the Webpartmanager loop through webparts, determine those that are minimised and set a variable / property within the webpart to inform it not to access the database on postback.
Something like...(pseudoCode)
for (int i = 0 ; i < webpartmanager1.webparts.count ; i++ )
webpart wp = (webpart)webpartmanager1.webpart[i];
if (wp != null)
if (wp.ChromeState == PartChromeState.Minimized)
{
// set a known variable in this particular webpart so it can determine whether to refresh its datagrid or gridview or whatever
}
}
OR
Can a usercontrol webpart determine its own ChromeState ????