Say I have a class called GenericFunctions and a function in there called FormatAddress.
If I want to access that function I have to do this:
Code:
GenericFunctions GF = new GenericFunctions();
string FormattedAddress = GF.FormatAddress(int AddressID);
If I make FormatAddress static I can access it without creating an instance of the class by just calling
Code:
string FormattedAddress = GenericFunctions.FormatAddress(int AddressID);
So, making the function Static means I don't have to create an instance of the class. So, what's the point? Why not make everything Static?
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(); }
I did some research after posting. All I found was simple examples for no-layer architectures, like connecting to a database from your aspx page, so, in a corporate environment, it is unnaceptable.
I need to call a server-side method (using ASP.NET Ajax) in a 3-layer architecture.
For example, my Default.aspx contains a method LoadProducts().
[Code]....
[Code]....
This cannot change. There is no way to convert Business and Data layers to static.
How can I call the LoadProducts() method using ASP.NET Ajax?
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>.
Just wondering, in an ASP.NET MVC3 environnement with entity framework. Should the Unit of Work point to the service layer or the repository (and then the repository point to the service layer) ?
Ive saw two example:
* One where the unit of work and repository both have an instance to the service layer..
Link: Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable
Doesn't use a service layer but its obvious that one could be use in that case.
* Second where the unit of work have an instance to the repository which have an instance to the service layer..
whats the exact use of static variables in overall programming in .net and for asp.net...
Recently i went for the interview where interviewer asked me 2 question which i was not sure for the same..
whats the use of session object, i said sessions are the server side object, they are used when you want to store user specific data at server side, then he asked what if i want to use static variables for the same, i was mum, can anyone tell me how asp.net will behave if i store the user specific information in static variables.If i use cookies which are the best option to store the data at client side (not sensitive one), but what if user has disabled cookies on his machine, will my application would crash.
What is the point of throwing an exception? It it anyways going to be caught in the Global.asax Application_Error method.
Lets say in the following code we throw an exception.
try { using (var dc = GetDataContext()) { // We are doing some data inserts here. } catch ( Exception ex) { throw ex; }
My Question: Even if we do not use try catch and throw here, any exception which will be raised here will be caught inside Application_Error method in Global.asax. Then what is the point of try, catch and throw in this case?
HTML5 is just an updating to XHTML 4.1 or it brings some thing different and new to the web world ,, what are the major differences between it and its predecessors..
I have been looking at the unit testing topic and honestly I have never yet seen it in a live application.
Im a little foggy on the subject.... A simple example is if I am populating a listbox with data, I would know through debugging if the data is being populated and if it wasnt it would probably be easy to figure out why. Futhermore I couldnt possibly put it in production if it wasnt work so, why would I need to do a unit test? I dont see the point of it.
Just created a blank "ASP.NET Web Application". Where's the entry point?
I see "Default.aspx" which seems to be the default template that calls. "Site.Master" which I guess acts as a layout file. "Global.asax" that seems to provide some method stubs for event handling. And then "Web.config" which seems to have some site-specific settings such as a DB connection string, and some authentication stuff.
But no where do I see any "routes" or anything to indicate that "Default.aspx" should be called by default, or "Global.asax" should be used to handle events. Where's this stuff specified? Is it baked into the core of ASP? Can't I filter all the requests through one C# method and then delegate how I please? And return some sort of Http response?
If I have a string/integer that looks like 123, how can I convert that to look like 12.3?Basically what I need is something faster (if possible) than thisMath.Round(Double.Parse(input / 1000), 1).ToString
I can't seem to achieve what I want which is to set the focus just to the left of the decimal point. I try both InputDirection RightToLeft and LeftToRight. They both have problematic behavior. The example given by Microsoft on their web site, is close to want I want but I cannot achieve these results.See
I want to create an asp.net white-label site [URL], that could be styled for each of our clients according to their specific needs. So for example, client abc would see the site in their corporate colours and be accessed through their specific url http://abc.com. Likewise client xyz would see the site in their own styling and url http://xyz.com.
Typing either url, in effect, takes the user to http://whitelabel.com where the styling is applied, and the client's url structure is retained.
I was thinking of URL rewriting using URLRewriter.Net [URL], or similar, mapping the incoming address to a client id and applying the theme accordingly. So, a url rewrite rule may be something like
I am working on imagemap, there are points on my image, I want to mark one of point upon clicking of a button, how can I can control the coordinates because my image is resizeable/dynamic, every time image size will be changed.
i am a c# dot net developer. i am given task to build a Pos application in c# for a grocery shop. i have no idea to develop it, please provide me if there is a tutorial, any class diagram or open source project
I can't seem to figure out how to set a breakpoint in a Razor view. I understand why that might seem a little weird and may be difficult since a cshtml file is a combination of html and then c# code, but I can step into it. The ability to step into it makes it seem like I should be able to set a breakpoint. Am I missing how to do this or is this not possible in the RC? If not any plans to add this before RTM or in the future?
The normal order for creating a web site is to creating a master page, then add a new web form and point it to the master page. However, I created my web form first, then created the master page. I am using 2008 express.
I noticed that while debugging. I had a break point on the page_Load but when it did the response.redirect and came to this page it did not hit the break point.